var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/hooks/useSearch.ts
var useSearch_exports = {};
__export(useSearch_exports, {
  useSearch: () => useSearch
});
module.exports = __toCommonJS(useSearch_exports);
var import_react = require("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] = (0, import_react.useState)(list);
  const [search, setSearch] = (0, import_react.useState)(initialSearch);
  (0, import_react.useEffect)(() => {
    setItems(list);
  }, [list]);
  const result = (0, import_react.useMemo)(
    () => MultiSearchWithMapping(search, items, searchMapping),
    [search, items, searchMapping]
  );
  return {
    result,
    hasResult: result.length > 0,
    allItems: items,
    setItems,
    search,
    setSearch
  };
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  useSearch
});
//# sourceMappingURL=useSearch.js.map