import { useEffect, useState, useMemo } from 'react';
import debounce from 'lodash/debounce';
import { QUICK_SEARCH_DEBOUNCE_TIME } from '../../Utilities/Constants/GeneralConstants';
export const useQuickSearchDebounced = (props) => {
    const [searchText, setSearchText] = useState(props.QuickSearchText ?? '');
    const debouncedRunQuickSearch = useMemo(() => debounce(props.onRunQuickSearch, QUICK_SEARCH_DEBOUNCE_TIME), [props.onRunQuickSearch]);
    useEffect(() => {
        setSearchText(props.QuickSearchText);
    }, [props.QuickSearchText]);
    const executeSearch = (searchText) => {
        setSearchText(searchText);
        debouncedRunQuickSearch(searchText);
    };
    return [searchText, executeSearch];
};
