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

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

  return (
    <Card>
      <FilterFieldWrapper onSearch={onSearch} testId='menu_filter'>
        <FilterField
          name='menuName'
          label='菜单名称'
          value={field.name}
          onChange={onChange('name')}
        />
        <FilterField
          name='modifyUser'
          label='修改人'
          value={field.modifyUser}
          onChange={onChange('modifyUser')}
        />
        <FilterButtonGroup
          onSearch={onSearch}
          isSearching={isSearching}
          onReset={onReset}
        />
      </FilterFieldWrapper>
    </Card>
  );
};

export default Filter;
