import { useState as h, useCallback as S, useEffect as y, useMemo as b } from "react";
import g from "../../_virtual/debounce.js";
import { useShopActions as P } from "../../internal/useShopActions.js";
import { useShopActionsPaginatedDataFetching as k } from "../../internal/useShopActionsPaginatedDataFetching.js";
const v = (s) => {
  const { getProductSearch: u } = P(), {
    query: e,
    filters: c,
    sortBy: n,
    includeSensitive: a = !1,
    skip: i = !1,
    ...d
  } = s ?? {}, [t, l] = h(e), r = S(
    g((p) => {
      l(p);
    }, 300),
    []
  );
  y(() => (r(e), () => {
    r.cancel();
  }), [e, r]);
  const { data: o, ...m } = k(
    u,
    {
      query: t,
      filters: c,
      sortBy: n,
      includeSensitive: a,
      ...d
    },
    {
      skip: i,
      hook: "useProductSearch"
    }
  ), f = b(() => t.trim().length === 0 ? null : o ?? null, [o, t]);
  return {
    ...m,
    products: f,
    isTyping: t !== e
  };
};
export {
  v as useProductSearch
};
//# sourceMappingURL=useProductSearch.js.map
