import _toLower from "lodash/fp/toLower";
import _includes from "lodash/fp/includes";
import _pipe from "lodash/fp/pipe";
import _filter from "lodash/fp/filter";
import _debounce from "lodash/fp/debounce";
import { useState, useCallback, useMemo } from 'react';
export const filterIcons = (query, allIcons) => {
  return query ? _filter(_pipe(_toLower, _includes(_toLower(query))), allIcons) : allIcons;
};
const useIconSearch = allIcons => {
  const [searchValue, setSearchValue] = useState('');
  const [searchResults, setSearchResults] = useState(allIcons);
  const updateSearchResults = useCallback(query => {
    const results = filterIcons(query, allIcons);
    setSearchResults(results);
  }, [allIcons]);
  const debouncedSearch = useMemo(() => _debounce(300, updateSearchResults), [updateSearchResults]);
  const handleSearch = useCallback(value => {
    setSearchValue(value);
    debouncedSearch(value);
  }, [debouncedSearch]);
  const handleReset = useCallback(() => {
    setSearchValue('');
    updateSearchResults('');
  }, [updateSearchResults]);
  return {
    searchValue,
    searchResults,
    handleSearch,
    handleReset
  };
};
export default useIconSearch;
//# sourceMappingURL=use-icon-search.js.map