import { Pagination, PaginationProps, Table } from "antd";
import { useState } from "react";
const BTable = (props: any) => {
  const { store, dataSource } = props;
  const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
  const onSelectChange = (newSelectedRowKeys: React.Key[]) => {
    setSelectedRowKeys(newSelectedRowKeys);
  };

  const rowSelection = {
    selectedRowKeys,
    onChange: onSelectChange,
  };
  const onShowSizeChange = (current, pageSize) => {
    store.setPages({
      PageNum: current,
      PageSize: pageSize,
    });
  };
  const onChange: PaginationProps["onChange"] = (page) => {
    store.setPages({
      PageNum: page,
      PageSize: 20,
    });
  };
  return (
    <>
      <Table
        style={{ height: "100%", overflow: "auto" }}
        pagination={false}
        // scroll={{ x: 'max-content' }}
        loading={store.listStatus}
        rowSelection={rowSelection}
        columns={props.columns}
        dataSource={dataSource}
      />
      <div style={{ textAlign: "right", padding: "10px" }}>
        <Pagination
          size="small"
          defaultCurrent={1}
          pageSize={20}
          showSizeChanger={true}
          total={store.total}
          onShowSizeChange={onShowSizeChange}
          onChange={onChange}
        />
      </div>
    </>
  );
};

export default BTable;
