import {FilterButtonGroup, FilterField, FilterFieldWrapper} 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='material_bind_filter'>
        <FilterField
          value={fields.wllbCode}
          label='物料编号'
          onChange={onChange('wllbCode')}
          name='wllbCode'
        />
        <FilterField
          value={fields.materialName}
          label='物料名称'
          onChange={onChange('materialName')}
          name='materialName'
        />
        <FilterField
          value={fields.userName}
          label='工号'
          onChange={onChange('userName')}
          name='userName'
        />
        <FilterField
          value={fields.realName}
          label='姓名'
          onChange={onChange('realName')}
          name='realName'
        />
        <FilterField
          value={fields.modifyUser}
          label='修改人'
          onChange={onChange('modifyUser')}
          name='modifyUser'
        />
        <FilterButtonGroup
          onSearch={onSearch}
          isSearching={isSearching}
          onReset={onReset}
        />
      </FilterFieldWrapper>
    </Card>
  );
};

export default Filter;
