import {Card} from 'antd';
import {FC} from 'react';
import GoodsModal from './modal';
import {useHandle, useList} from './hooks';
import {pageContext, searchContext} from '../context';
import {Table, TableTools} from '@components';

const TableList: FC = function() {
  const [{data, count}, {refetch}] = useList();
  const [{visible, editId, columns}, {onAdd, onClose}] = useHandle(refetch);

  return (
    <>
      <Card className='table-wrapper'>
        <TableTools onClick={onAdd} />

        <Table
          data-testid='goods_table'
          columns={columns}
          data={data}
          pageContext={pageContext}
          searchContext={searchContext}
          count={count}
          scrollX={2600}
        />
      </Card>

      <GoodsModal
        visible={visible}
        id={editId}
        onClose={onClose}
        onFetch={refetch}
      />
    </>
  );
};

export default TableList;
