import {exportOrderDeleteList, getDeleteLogList} from '@apis';
import {
  useContextSection,
  useQueryTableList,
  useTableExportEvent,
} from '@hooks';
import {DeleteLogListData} from '@models';
import {
  MAXIMAL_TABLE_WIDTH,
  MIDDLE_TABLE_WIDTH,
  NORMAL_TABLE_WIDTH,
} from '@utils';
import {Card} from 'antd';
import {ColumnsType} from 'antd/es/table';
import {FC} from 'react';
import {context, pageContext, searchContext} from '../context';
import {Table, TableTools} from '@components';

const columns: ColumnsType<DeleteLogListData> = [
  {title: '操作用户', dataIndex: 'userName', width: NORMAL_TABLE_WIDTH},
  {title: '单据类型', dataIndex: 'documentType', width: NORMAL_TABLE_WIDTH},
  {title: '删除数据', dataIndex: 'data', width: MAXIMAL_TABLE_WIDTH},
  {title: '删除时间', dataIndex: 'scrq', width: MIDDLE_TABLE_WIDTH},
];

const TableList: FC = function () {
  const params = useContextSection(context, state => state[0]);
  const [{data, count}] = useQueryTableList({
    queryFn: getDeleteLogList,
    params,
    pageContext,
    searchContext,
  });
  const [isExporting, onExport] = useTableExportEvent({
    pageContext,
    context,
    fn: exportOrderDeleteList,
  });

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

      <Table
        pageContext={pageContext}
        searchContext={searchContext}
        columns={columns}
        data={data}
        count={count}
        data-testid='order_log_table'
      />
    </Card>
  );
};

export default TableList;
