import {FilterButtonGroup, FilterField} from '@components';
import {Card, Row} from 'antd';
import {FC} from 'react';
import {useExport, useField, useSearch} from './hooks';
import {useContextSection} from '@hooks';
import {context} from '../context';

const Filter: FC = function() {
  const [{name, code}, onChange] = useField();
  const onSearch = useSearch(name, code);
  const [isExporting, onExport] = useExport();
  const isSearching = useContextSection(context, state => state[0].isSearching);

  return (
    <Card>
      <Row>
        <FilterField name='departmentCode' label='部门编号' value={code} onChange={onChange('code')} />
        <FilterField name='departmentName' label='部门名称' value={name} onChange={onChange('name')} />
        <FilterButtonGroup
          isExporting={isExporting}
          isSearching={isSearching}
          onSearch={onSearch}
          onExport={onExport}
          offset={6}
        />
      </Row>
    </Card>
  );
};

export default Filter;
