import { R as i, t as y, U as P, V as A, q as R, A as $ } from "./index-jYYVpIDL.js";
import { useMemo as Q, useEffect as d, useCallback as b, useState as x, useRef as L } 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 w(r) {
  const o = y.useRouter(), c = P(), u = y.usePathname(), a = r.safeParse(c);
  let s = Q(() => ({}), []);
  d(() => {
    a.success && a.data && Object.entries(a.data).forEach(([e, t]) => {
      if (e in c || !t)
        return;
      const n = new URLSearchParams(s);
      n.set(String(e), String(t)), o.replace(`${u}?${n.toString()}`);
    });
  }, [a, r, o, u, c, s]), a.success ? s = a.data : a.success || console.error(a.error);
  const m = b(
    function(t, n) {
      const p = new URLSearchParams(s);
      p.set(String(t), String(n)), 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 n = s[e];
    if (Array.isArray(n)) {
      if (n.includes(t))
        return;
      m(e, [...n, t]);
    } else
      m(e, [t]);
  }
  function h(e, t) {
    const n = s[e];
    if (Array.isArray(n) && n.length > 1) {
      const p = n.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 U = i.object({ hl: i.string().optional() });
function C(r) {
  const { slug: o, shouldHighlight: c } = r, {
    data: { hl: u }
  } = w(U), a = y.useRouter(), [s, m] = x(c && u === o), l = L(null), f = A(), 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();
    a.replace(`${h}${e !== "" ? `?${e}` : ""}`);
  }, 3e3)), () => {
    l.current && (clearTimeout(l.current), l.current = null);
  }), [s, h, a, f, c]), /* @__PURE__ */ R.jsx($, { ...r });
}
export {
  C as default
};
