import { useState, useEffect} from 'react' import { useLocation } from 'react-router-dom'; import { Loader, Search } from "lucide-react" import HeaderMenu from '@/layout/HeaderMenu' import HeaderMenuComponents from '@/layout/HeaderMenu.component' import HeaderMenuBreadCrumb from '@/layout/HeaderMenu.breadcrumb' import Footer from '@/layout/Footer' import { useSearchData } from '@/reducer/linkFetchReducer' import SearchBar from '@/layout/SearchBar.component' import ProgressBar from '@/layout/ProgressBar'; function Layout({ children }) { const [searchQuery, setSearchQuery] = useState('') const [triggerSearch, setTriggerSearch] = useState(false) const [debouncedQuery, setDebouncedQuery] = useState('') const { loading, searchContent, error } = useSearchData(debouncedQuery, triggerSearch) const location = useLocation() const handleSearchSubmit = (query) => { document.body.style.cursor = "wait" setSearchQuery(query) setTriggerSearch(true) }; const handleInputChange = (event) => { setSearchQuery(event.target.value) }; const handleSubmit = (event) => { event.preventDefault() handleSearchSubmit(searchQuery) }; useEffect(() => { const delayDebounceFn = setTimeout(() => { setDebouncedQuery(searchQuery); }, 800); return () => clearTimeout(delayDebounceFn); }, [searchQuery]); useEffect(() => { setSearchQuery(''); setTriggerSearch(false); }, [location.pathname]); useEffect(() => { if (searchQuery === '') { setTriggerSearch(false); } }, [searchQuery]); useEffect(() => { if (!loading) { document.body.style.cursor = "default"; } }, [loading]); useEffect(() => { const timer = setTimeout(() => { document.body.style.cursor = "default"; }, 900); return () => clearTimeout(timer); }, []); return ( <>