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

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

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

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

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

export default TableList;
