'use client'; import { useEffect, useState } from 'react'; import { IconChild } from '@/components/Icons'; import SelectGraphFilter from '@/components/select/SelectGraphFilter'; import SelectMatchMode from '@/components/select/SelectMatchMode'; import MiniButton from '@/components/ui/MiniButton'; import SearchBar from '@/components/ui/SearchBar'; import useLocalStorage from '@/hooks/useLocalStorage'; import { CstMatchMode, DependencyMode } from '@/models/miscellaneous'; import { applyGraphFilter } from '@/models/miscellaneousAPI'; import { ConstituentaID, IConstituenta, IRSForm } from '@/models/rsform'; import { matchConstituenta } from '@/models/rsformAPI'; import { storage } from '@/utils/constants'; interface ConstituentsSearchProps { schema?: IRSForm; dense?: boolean; activeID?: ConstituentaID; activeExpression: string; setFiltered: React.Dispatch>; } function ConstituentsSearch({ schema, activeID, activeExpression, dense, setFiltered }: ConstituentsSearchProps) { const [filterMatch, setFilterMatch] = useLocalStorage(storage.cstFilterMatch, CstMatchMode.ALL); const [filterSource, setFilterSource] = useLocalStorage(storage.cstFilterGraph, DependencyMode.ALL); const [filterText, setFilterText] = useState(''); const [showInherited, setShowInherited] = useLocalStorage(storage.cstFilterShowInherited, true); useEffect(() => { if (!schema || schema.items.length === 0) { setFiltered([]); return; } let result: IConstituenta[] = []; if (!activeID) { result = schema.items; } else { result = applyGraphFilter(schema, activeID, filterSource); } if (filterText) { result = result.filter(cst => matchConstituenta(cst, filterText, filterMatch)); } if (!showInherited) { result = result.filter(cst => !cst.is_inherited); } setFiltered(result); }, [ filterText, setFiltered, filterSource, activeExpression, schema?.items, schema, filterMatch, activeID, showInherited ]); return (
setFilterMatch(newValue)} dense={dense} /> setFilterSource(newValue)} dense={dense} /> {schema && schema?.stats.count_inherited > 0 ? ( ${showInherited ? 'отображать' : 'скрывать'}`} icon={} className='h-fit self-center' onClick={() => setShowInherited(prev => !prev)} /> ) : null}
); } export default ConstituentsSearch;