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

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

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

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

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

export default TableList;
