import { useState as p, useMemo as C, useCallback as b, useEffect as k } from "react";
import { detailedGroups as a } from "../../constants/index.js";
const y = (o, { searchFields: t, searchTypes: r }) => {
  const [h, m] = p(!1), [v, l] = p(a), i = o.toLowerCase(), d = C(
    () => a.map((e) => ({
      ...e,
      items: e.items.filter((n) => {
        const u = [];
        return t.includes("productName") && u.push(n.value), t.includes("sku") && u.push(n.value), t.includes("asin") && u.push(n.value), t.includes("gtin") && u.push(n.value), u.some((f) => {
          const s = f == null ? void 0 : f.toLowerCase();
          return r.includes("exact") ? s === i : r.includes("beginsWith") ? s == null ? void 0 : s.startsWith(i) : s == null ? void 0 : s.includes(i);
        });
      })
    })).filter((e) => e.items.length > 0),
    [i, t, r]
  ), c = b(async () => {
    m(!0);
    try {
      if (await new Promise((e) => setTimeout(e, 300)), !o.trim()) {
        l(a);
        return;
      }
      l(d);
    } catch (e) {
      console.error("Query error:", e), l([]);
    } finally {
      m(!1);
    }
  }, [d, o]);
  return k(() => {
    c();
  }, [c]), { isLoading: h, groups: v, refetch: c };
};
export {
  y as default
};
//# sourceMappingURL=useArticleQuery.js.map
