/* eslint-disable @typescript-eslint/no-explicit-any */ import { useState, useEffect, useRef } from "react"; import AdvancedSearchView from "./AdvancedSearchView"; import FilterPopup from "./FilterPopup"; import { FilterTarget } from "../../data/advancedSearch"; import { useFilterData } from "./helper/useFilterData"; type AdvancedSearchProps = { visible: boolean; disabled: boolean; enableCustomView?: boolean; filterableFields: FilterTarget[]; uiElementGroupData: Record; config: { uiElementGroupId: string }; onModelUpdate: ( callBack: ((args: any) => void) | null, fieldName: string, value: any, ) => void; loadTemplateSupportiveData?: ( callBack: (args: any) => void, supportiveKeys: any, ) => Promise; }; const AdvancedSearch: React.FC = (props) => { const { loadSupportiveData, cache } = useFilterData({ loadTemplateSupportiveData: props.loadTemplateSupportiveData, }); const [togglePopup, setTogglePopup] = useState(false); const popupRef = useRef(null); const handlePopupShow = () => { setTogglePopup(!togglePopup); }; const handleClickOutside = (event: MouseEvent) => { const target = event.target as HTMLElement; const isInsideMyPopup = target.closest(`.tmpl-prvent-outside-click-close`); if ( popupRef.current && !popupRef.current.contains(event.target as Node) && !isInsideMyPopup ) { setTogglePopup(false); } }; useEffect(() => { if (togglePopup) { document.addEventListener("mousedown", handleClickOutside); } else { document.removeEventListener("mousedown", handleClickOutside); } return () => { document.removeEventListener("mousedown", handleClickOutside); }; }, [togglePopup]); return props.visible ? (
0) } /> {togglePopup && !props.disabled && (
e.stopPropagation()} >
)}
) : ( <> ); }; export default AdvancedSearch;