import {Card} from 'antd';
import {FC} from 'react';
import {context, pageContext, searchContext} from '../context';
import {Table, TableTools} from '@components';
import {getUnBindList} from '@apis';
import {useContextSection, useQueryTableList} from '@hooks';
import {ColumnsType} from 'antd/es/table';
import {UnBindListData} from '@models';
import {
  MATERIAL_CODE_COL_WIDTH,
  MATERIAL_NAME_COL_WIDTH,
  MIDDLE_TABLE_WIDTH,
} from '@utils';

const columns: ColumnsType<UnBindListData> = [
  {title: '物料ID', dataIndex: 'material_id', width: MATERIAL_CODE_COL_WIDTH},
  {title: '物料编号', dataIndex: 'code', width: MATERIAL_CODE_COL_WIDTH},
  {title: '物料名称', dataIndex: 'name', width: MATERIAL_NAME_COL_WIDTH},
  {title: '日期', dataIndex: 'scrq', width: MIDDLE_TABLE_WIDTH},
];

const TableList: FC = function() {
  const params = useContextSection(context, state => state[0]);
  const [{data, count}] = useQueryTableList({
    queryFn: getUnBindList,
    params,
    pageContext,
    searchContext,
  });

  return (
    <>
      <Card className="table-wrapper">
        <TableTools
          searchContext={searchContext}
          pageContext={pageContext}
        />

        <Table
          data-testid="role_table"
          columns={columns}
          data={data}
          pageContext={pageContext}
          searchContext={searchContext}
          count={count}
        />
      </Card>

    </>
  );
};

export default TableList;
