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