"use strict";

exports.__esModule = true;
exports.filterIcons = exports.default = void 0;
var _toLower2 = _interopRequireDefault(require("lodash/fp/toLower"));
var _includes2 = _interopRequireDefault(require("lodash/fp/includes"));
var _pipe2 = _interopRequireDefault(require("lodash/fp/pipe"));
var _filter2 = _interopRequireDefault(require("lodash/fp/filter"));
var _debounce2 = _interopRequireDefault(require("lodash/fp/debounce"));
var _react = require("react");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const filterIcons = (query, allIcons) => {
  return query ? (0, _filter2.default)((0, _pipe2.default)(_toLower2.default, (0, _includes2.default)((0, _toLower2.default)(query))), allIcons) : allIcons;
};
exports.filterIcons = filterIcons;
const useIconSearch = allIcons => {
  const [searchValue, setSearchValue] = (0, _react.useState)('');
  const [searchResults, setSearchResults] = (0, _react.useState)(allIcons);
  const updateSearchResults = (0, _react.useCallback)(query => {
    const results = filterIcons(query, allIcons);
    setSearchResults(results);
  }, [allIcons]);
  const debouncedSearch = (0, _react.useMemo)(() => (0, _debounce2.default)(300, updateSearchResults), [updateSearchResults]);
  const handleSearch = (0, _react.useCallback)(value => {
    setSearchValue(value);
    debouncedSearch(value);
  }, [debouncedSearch]);
  const handleReset = (0, _react.useCallback)(() => {
    setSearchValue('');
    updateSearchResults('');
  }, [updateSearchResults]);
  return {
    searchValue,
    searchResults,
    handleSearch,
    handleReset
  };
};
var _default = exports.default = useIconSearch;
//# sourceMappingURL=use-icon-search.js.map