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

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

  return (
    <Card>
      <FilterFieldWrapper onSearch={onSearch} testId='matter_filter'>
        <FilterField
          value={fields.wllbCode}
          label='物料编号'
          onChange={onChange('wllbCode')}
          name='wllbCode'
        />
        <FilterField
          value={fields.wllbName}
          label='物料名称'
          onChange={onChange('wllbName')}
          name='wllbName'
        />
        <FilterField
          value={fields.storageLocationCode}
          label='库位编号'
          onChange={onChange('storageLocationCode')}
          name='storageLocationCode'
        />
        <FilterField
          value={fields.storageLocationName}
          label='库位名称'
          onChange={onChange('storageLocationName')}
          name='storageLocationName'
        />
        <FilterField
          value={fields.modifyUser}
          label='修改人'
          onChange={onChange('modifyUser')}
          name='modifyUser'
        />
        <FilterButtonGroup
          onSearch={onSearch}
          isSearching={isSearching}
          onReset={onReset}
        />
      </FilterFieldWrapper>
    </Card>
  );
};

export default Filter;
