import {Card} from 'antd';
import {FC} from 'react';
import MenuModal 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 [{columns, visible, editId}, {onModalClose, onAdd}] = useHandle(data, refetch);

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

        <Table
          data-testid='child_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;
