{"version":3,"file":"index.js","names":["React","useEffect","useRef","useState","useDebounce","baseClass","SearchFilter","props","handleChange","initialParams","label","searchQueryParam","searchParam","search","setSearch","undefined","shouldUpdateState","previousSearch","debouncedSearch","current","_jsx","className","id","onChange","e","target","value","placeholder","type"],"sources":["../../../src/elements/SearchFilter/index.tsx"],"sourcesContent":["'use client'\n\nimport React, { useEffect, useRef, useState } from 'react'\n\nimport type { SearchFilterProps } from './types.js'\n\nimport { useDebounce } from '../../hooks/useDebounce.js'\nimport './index.scss'\n\nconst baseClass = 'search-filter'\n\nexport function SearchFilter(props: SearchFilterProps) {\n const { handleChange, initialParams, label, searchQueryParam } = props\n const searchParam = initialParams?.search || searchQueryParam\n const [search, setSearch] = useState(typeof searchParam === 'string' ? searchParam : undefined)\n\n /**\n * Tracks whether the state should be updated based on the search value.\n * If the value is updated from the URL, we don't want to update the state as it causes additional renders.\n */\n const shouldUpdateState = useRef(true)\n\n /**\n * Tracks the previous search value to compare with the current debounced search value.\n */\n const previousSearch = useRef(typeof searchParam === 'string' ? searchParam : undefined)\n\n const debouncedSearch = useDebounce(search, 300)\n\n useEffect(() => {\n if (searchParam !== previousSearch.current) {\n shouldUpdateState.current = false\n setSearch(searchParam as string)\n previousSearch.current = searchParam as string\n }\n\n return () => {\n shouldUpdateState.current = true\n previousSearch.current = undefined\n }\n }, [searchParam])\n\n useEffect(() => {\n if (debouncedSearch !== previousSearch.current && shouldUpdateState.current) {\n if (handleChange) {\n handleChange(debouncedSearch)\n }\n\n previousSearch.current = debouncedSearch\n }\n }, [debouncedSearch, handleChange])\n\n return (\n