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

const TableList: FC = function() {
  const [
    {count, data},
    {refetch},
  ] = useList();
  const [
    {modalVisible, columns, editState},
    {onAdd, setFalse},
  ] = useHandle(refetch);

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

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

      <Modal visible={modalVisible} onClose={setFalse} onFetch={refetch} id={editState} />
    </>
  );
};

export default TableList;
