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

  const rowSelection = {
    selectedRowKeys,
    onChange: onSelectChange,
  };
  const onShowSizeChange = (current, pageSize) => {
    store.setPages({
      Offset: current,
      Size: pageSize,
    });
  };
  const onChange: PaginationProps["onChange"] = (page) => {
    store.setPages({
      Offset: page,
      Size: 20,
    });
  };
  return (
    <>
      <Table
        style={{ height: "100%", overflow: "auto" }}
        pagination={false}
        scroll={scroll }
        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;
