// src/hooks/useSearch.ts
import { useEffect, useMemo, useState } from "react";

// src/util/simpleSearch.ts
var MultiSearchWithMapping = (search, objects, mapping) => {
  return objects.filter((object) => {
    const mappedSearchKeywords = mapping(object)?.map((value) => value.toLowerCase().trim());
    if (!mappedSearchKeywords) {
      return true;
    }
    return !!mappedSearchKeywords.find((value) => value.includes(search.toLowerCase().trim()));
  });
};

// src/hooks/useSearch.ts
var useSearch = ({
  list,
  initialSearch,
  searchMapping
}) => {
  const [items, setItems] = useState(list);
  const [search, setSearch] = useState(initialSearch);
  useEffect(() => {
    setItems(list);
  }, [list]);
  const result = useMemo(
    () => MultiSearchWithMapping(search, items, searchMapping),
    [search, items, searchMapping]
  );
  return {
    result,
    hasResult: result.length > 0,
    allItems: items,
    setItems,
    search,
    setSearch
  };
};
export {
  useSearch
};
//# sourceMappingURL=useSearch.mjs.map