import {FilterButtonGroup, FilterField, FilterFieldWrapper} from '@components';
import {
  useContextSection,
  useFilterField,
  useTableSearchToolEvents,
} from '@hooks';
import {Card} from 'antd';
import {FC} from 'react';
import {context, searchContext} from '../context';

const Filter: FC = function () {
  const {isSearching} = useContextSection(searchContext, state => state[0]);
  const [fields, {onChange, resetState}] = useFilterField(
    {
      wllbCode: '',
      materialName: '',
    },
    true,
  );
  const [, {onSearch, onReset}] = useTableSearchToolEvents(context, fields, {
    resetCallback: resetState,
  });

  return (
    <Card>
      <FilterFieldWrapper onSearch={onSearch} testId='reserves_warning_filter'>
        <FilterField
          value={fields.wllbCode}
          label='物料编号'
          onChange={onChange('wllbCode')}
          name='wllbCode'
        />
        <FilterField
          value={fields.materialName}
          label='物料名称'
          onChange={onChange('materialName')}
          name='materialName'
        />
        <FilterButtonGroup
          onSearch={onSearch}
          isSearching={isSearching}
          onReset={onReset}
        />
      </FilterFieldWrapper>
    </Card>
  );
};

export default Filter;
