import {useContextSection, useQueryTableList} from '@hooks';
import {FC} from 'react';
import {context, pageContext, searchContext} from '../context';
import {getOtherOut} from '@apis';
import {useColumns} from './hooks';
import {Table, TableTools} from '@components';
import {Card} from 'antd';

const TableList: FC = function () {
  const params = useContextSection(context, state => state[0]);
  const [{data, count, isFetching}, {refetch}] = useQueryTableList({
    queryFn: getOtherOut,
    pageContext,
    searchContext,
    params,
  });
  const columns = useColumns(refetch);

  return (
    <Card className='table-wrapper'>
      <TableTools isRefreshing={isFetching} onRefresh={refetch} />

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

export default TableList;
