import { jsx as P } from "react/jsx-runtime";
import { a6 as i, G as y, a7 as A, a8 as R, A as $ } from "./index-_1f6rhg6.js";
import { useMemo as Q, useEffect as d, useCallback as b, useState as L, useRef as w } from "react";
i.string().or(i.number()).or(i.array(i.number())).transform((r) => typeof r == "string" ? r.split(",").map((o) => Number(o)) : Array.isArray(r) ? r : [r]);
i.preprocess((r) => i.string().parse(r).split(","), i.string().array()).or(i.string().array());
function x(r) {
  const o = y.useRouter(), c = A(), u = y.usePathname(), n = r.safeParse(c);
  let s = Q(() => ({}), []);
  d(() => {
    n.success && n.data && Object.entries(n.data).forEach(([e, t]) => {
      if (e in c || !t)
        return;
      const a = new URLSearchParams(s);
      a.set(String(e), String(t)), o.replace(`${u}?${a.toString()}`);
    });
  }, [n, r, o, u, c, s]), n.success ? s = n.data : n.success || console.error(n.error);
  const m = b(
    function(t, a) {
      const p = new URLSearchParams(s);
      p.set(String(t), String(a)), o.replace(`${u}?${p.toString()}`);
    },
    // eslint-disable-next-line react-hooks/exhaustive-deps
    [s, o]
  );
  function l(e) {
    const t = new URLSearchParams(s);
    t.delete(String(e)), o.replace(`${u}?${t.toString()}`);
  }
  function f(e, t) {
    const a = s[e];
    if (Array.isArray(a)) {
      if (a.includes(t))
        return;
      m(e, [...a, t]);
    } else
      m(e, [t]);
  }
  function h(e, t) {
    const a = s[e];
    if (Array.isArray(a) && a.length > 1) {
      const p = a.filter((S) => S !== t);
      m(e, p);
    } else
      l(e);
  }
  function g() {
    u !== null && o.replace(u);
  }
  return {
    data: s,
    setQuery: m,
    removeByKey: l,
    pushItemToKey: f,
    removeItemByKeyAndValue: h,
    removeAllQueryParams: g
  };
}
const C = i.object({ hl: i.string().optional() });
function j(r) {
  const { slug: o, shouldHighlight: c } = r, {
    data: { hl: u }
  } = x(C), n = y.useRouter(), [s, m] = L(c && u === o), l = w(null), f = R(), h = y.usePathname();
  return d(() => (c && s && f !== null && h !== null && (l.current = setTimeout(() => {
    const g = new URLSearchParams(f.toString());
    g.delete("hl"), g.delete("category"), m(!1);
    const e = g.toString();
    n.replace(`${h}${e !== "" ? `?${e}` : ""}`);
  }, 3e3)), () => {
    l.current && (clearTimeout(l.current), l.current = null);
  }), [s, h, n, f, c]), /* @__PURE__ */ P($, { ...r });
}
export {
  j as default
};
