import {Card} from 'antd';
import {FC} from 'react';
import StorageModal from './modal';
import {pageContext, searchContext} from '../context';
import {useHandle, useList} from './hooks';
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='storage_table'
          columns={columns}
          data={data}
          pageContext={pageContext}
          searchContext={searchContext}
          count={count}
        />
      </Card>

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

export default TableList;
