import { DageTableActions } from "@dage/pc-components";
import { Button, Table } from "antd";
import { useCallback, useMemo, useState } from "react";
import { useNavigate } from "react-router-dom";

const DEFAULT_PARAMS = {
  pageNum: 1,
  pageSize: 20,
};

export default function BannerPage() {
  const navigate = useNavigate();
  const [list, setList] = useState<[]>([]);
  const [total, setTotal] = useState(0);
  const [loading, setLoading] = useState(false);
  const [params, setParams] = useState({
    ...DEFAULT_PARAMS,
  });

  const paginationChange = useCallback(
    () => (pageNum: number, pageSize: number) => {
      setParams({ ...params, pageNum, pageSize });
    },
    [params]
  );

  const COLUMNS = useMemo(() => {
    return [
      {
        title: "海报",
        dataIndex: "userName",
      },
      {
        title: "发布日期",
        dataIndex: "nickName",
      },
      {
        title: "操作",
        render: (item: any) => {
          return <DageTableActions onEdit={() => {}} onDelete={() => {}} />;
        },
      },
    ];
  }, []);

  return (
    <div>
      <div style={{ textAlign: "right" }}>
        <Button type="primary" onClick={() => navigate("/banner/create")}>
          新增
        </Button>
      </div>

      <Table
        loading={loading}
        className="page-table"
        dataSource={list}
        columns={COLUMNS}
        rowKey="id"
        pagination={{
          showQuickJumper: true,
          position: ["bottomCenter"],
          showSizeChanger: true,
          current: params.pageNum,
          pageSize: params.pageSize,
          total,
          onChange: paginationChange(),
        }}
      />
    </div>
  );
}
