import { jsx as F, Fragment as G } from "react/jsx-runtime";
import W, { forwardRef as $, createContext as Y, useContext as X, useEffect as J, useState as K, useRef as xe, useImperativeHandle as _e, useMemo as Ue, Children as $e, isValidElement as Ne } from "react";
function Ce() {
}
const { stringify: Ve } = JSON, Ae = String, Te = "string", qe = "object", Be = (e, t) => t, oe = (e, t, r) => {
  const n = Ae(t.push(r) - 1);
  return e.set(r, n), n;
}, He = (e, t, r) => {
  const n = Be, a = /* @__PURE__ */ new Map(), v = [], g = [];
  let o = +oe(a, v, n.call({ "": e }, "", e)), s = !o;
  for (; o < v.length; )
    s = !0, g[o] = Ve(v[o++], w, r);
  return "[" + g.join(",") + "]";
  function w(c, P) {
    if (s)
      return s = !s, P;
    const y = n.call(this, c, P);
    switch (typeof y) {
      case qe:
        if (y === null) return y;
      case Te:
        return a.get(y) || oe(a, v, y);
    }
    return y;
  }
};
var le = { exports: {} }, j = {};
/*
object-assign
(c) Sindre Sorhus
@license MIT
*/
var z, ce;
function Ke() {
  if (ce) return z;
  ce = 1;
  var e = Object.getOwnPropertySymbols, t = Object.prototype.hasOwnProperty, r = Object.prototype.propertyIsEnumerable;
  function n(v) {
    if (v == null)
      throw new TypeError("Object.assign cannot be called with null or undefined");
    return Object(v);
  }
  function a() {
    try {
      if (!Object.assign)
        return !1;
      var v = new String("abc");
      if (v[5] = "de", Object.getOwnPropertyNames(v)[0] === "5")
        return !1;
      for (var g = {}, o = 0; o < 10; o++)
        g["_" + String.fromCharCode(o)] = o;
      var s = Object.getOwnPropertyNames(g).map(function(c) {
        return g[c];
      });
      if (s.join("") !== "0123456789")
        return !1;
      var w = {};
      return "abcdefghijklmnopqrst".split("").forEach(function(c) {
        w[c] = c;
      }), Object.keys(Object.assign({}, w)).join("") === "abcdefghijklmnopqrst";
    } catch {
      return !1;
    }
  }
  return z = a() ? Object.assign : function(v, g) {
    for (var o, s = n(v), w, c = 1; c < arguments.length; c++) {
      o = Object(arguments[c]);
      for (var P in o)
        t.call(o, P) && (s[P] = o[P]);
      if (e) {
        w = e(o);
        for (var y = 0; y < w.length; y++)
          r.call(o, w[y]) && (s[w[y]] = o[w[y]]);
      }
    }
    return s;
  }, z;
}
/** @license React v17.0.2
 * react-jsx-runtime.production.min.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
var ue;
function ze() {
  if (ue) return j;
  ue = 1, Ke();
  var e = W, t = 60103;
  if (j.Fragment = 60107, typeof Symbol == "function" && Symbol.for) {
    var r = Symbol.for;
    t = r("react.element"), j.Fragment = r("react.fragment");
  }
  var n = e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner, a = Object.prototype.hasOwnProperty, v = { key: !0, ref: !0, __self: !0, __source: !0 };
  function g(o, s, w) {
    var c, P = {}, y = null, k = null;
    w !== void 0 && (y = "" + w), s.key !== void 0 && (y = "" + s.key), s.ref !== void 0 && (k = s.ref);
    for (c in s) a.call(s, c) && !v.hasOwnProperty(c) && (P[c] = s[c]);
    if (o && o.defaultProps) for (c in s = o.defaultProps, s) P[c] === void 0 && (P[c] = s[c]);
    return { $$typeof: t, type: o, key: y, ref: k, props: P, _owner: n.current };
  }
  return j.jsx = g, j.jsxs = g, j;
}
var fe;
function Me() {
  return fe || (fe = 1, le.exports = ze()), le.exports;
}
var L = Me();
const Ge = () => {
  try {
    if (typeof localStorage > "u")
      return !1;
    const e = "debug-test";
    localStorage.setItem(e, e);
    const t = localStorage.getItem(e) === e;
    if (localStorage.removeItem(e), !t)
      return !1;
  } catch (e) {
    return console.error("[debugUtils]: Debug mode is disabled (localStorage unavailable).", e), !1;
  }
  return (localStorage.getItem("debug") ?? "").includes("enable-debug");
}, pe = Ge();
function I(e, ...t) {
  if (!pe)
    return;
  const r = Je(e, ...t);
  performance.mark(r), console.log(`[DEBUG]: ${r}`, ...t);
}
function We(e, ...t) {
  pe && console.warn(`[WARN]: ${e}`, ...t);
}
function Je(e, ...t) {
  return e.replace(/%[sfdO]/g, (r) => {
    const n = t.shift();
    if (r === "%O" && n)
      try {
        return He(n);
      } catch (a) {
        return console.error("Error stringifying object", a), "[Circular Object]";
      }
    else
      return String(n);
  });
}
const Ye = {
  parse: (e) => e,
  serialize: (e) => String(e)
}, dt = {
  parse: (e) => e === "true",
  serialize: (e) => e === !0 ? "true" : e === !1 ? "false" : ""
}, Xe = ({
  filterKey: e,
  children: t,
  parser: r = Ye,
  className: n
}) => {
  const { updateFilter: a, getFilterValue: v, removeFilter: g } = Z(), o = (c) => {
    const P = r.serialize(c);
    a(e, P, c);
  }, s = (c) => {
    g(c ?? e);
  }, w = v(e);
  return /* @__PURE__ */ L.jsx("div", { id: `filter-${String(e)}`, className: n, children: t({
    onChange: o,
    value: w,
    removeFilter: s
  }) });
};
var S = /* @__PURE__ */ ((e) => (e.VISIBLE = "VISIBLE", e.FILTER_APPLIED = "FILTER_APPLIED", e.HIDDEN = "HIDDEN", e))(S || {});
const Ze = ({ children: e, className: t }) => {
  const { visibleFilters: r, addInitialFilters: n } = Z(), a = {
    components: [],
    filtersConfig: {}
  };
  J(() => {
    n(g);
  }, []);
  const { components: v, filtersConfig: g } = W.Children.toArray(e).reduce((o, s) => (W.isValidElement(s) && s.props.filterKey !== null && typeof s.props.filterKey == "string" && (r.includes(s.props.filterKey) && o.components.push(s), o.filtersConfig[s.props.filterKey] = {
    defaultValue: s.props.defaultValue,
    parser: s.props.parser,
    isSticky: s.props.sticky,
    state: S.HIDDEN
  }), o), a);
  return /* @__PURE__ */ L.jsx("div", { className: t, children: v });
}, Qe = ({ children: e }) => {
  const { addFilter: t, availableFilters: r, resetFilters: n } = Z();
  return e((a) => {
    t(a);
  }, r, n);
}, et = { ...window.location, state: {}, key: "" }, tt = (e) => {
  typeof e == "number" ? window.history.go(e) : window.location.href = e.toString();
}, ge = Y({
  location: et,
  navigate: tt
}), rt = () => X(ge), nt = ({
  children: e,
  location: t,
  navigate: r
}) => /* @__PURE__ */ L.jsx(
  ge.Provider,
  {
    value: {
      location: t,
      navigate: r
    },
    children: e
  }
), M = (e) => new URLSearchParams(e);
function st() {
  const { navigate: e, location: t } = rt();
  return {
    searchParams: Ue(() => M(t.search), [t.search]),
    push: (r, n) => {
      const a = n ? `?${M(n).toString()}` : "";
      e(`${r}${a}`, { replace: !1 });
    },
    replace: (r, n) => {
      const a = n ? `?${M(n).toString()}` : "";
      e(`${r}${a}`, { replace: !0 });
    },
    updateURL: (r, n = !1) => {
      const a = `?${r.toString()}`, v = t.pathname;
      n ? e(`${v}${a}`, { replace: !0 }) : e(`${v}${a}`, { replace: !1 });
    }
  };
}
function it(e) {
  if (e.size === 0)
    return "";
  const t = [];
  for (const [r, n] of e.entries()) {
    const a = r.replace(/#/g, "%23").replace(/&/g, "%26").replace(/\+/g, "%2B").replace(/=/g, "%3D").replace(/\?/g, "%3F");
    t.push(`${a}=${at(n)}`);
  }
  return "?" + t.join("&");
}
function at(e) {
  return e.replace(/%/g, "%25").replace(/\+/g, "%2B").replace(/ /g, "+").replace(/#/g, "%23").replace(/&/g, "%26").replace(/"/g, "%22").replace(/'/g, "%27").replace(/`/g, "%60").replace(/</g, "%3C").replace(/>/g, "%3E").replace(/[\x00-\x1F]/g, (t) => encodeURIComponent(t));
}
const D = (e, t) => {
  const r = e.reduce((n, a) => {
    var v, g;
    if (((v = t[a]) == null ? void 0 : v.state) === S.FILTER_APPLIED && ((g = t[a]) == null ? void 0 : g.persistInURL) !== !1) {
      const o = a;
      return n ? (
        // @ts-ignore
        `${n}&${o}=${t[o].query}`
      ) : `${o}=${t[o].query}`;
    }
    return n;
  }, "");
  return it(new URLSearchParams(r ? `?${r}` : ""));
};
function ot(e, t) {
  const r = new URLSearchParams(e.toString());
  for (const [n, a] of t)
    !a && a !== "false" ? r.delete(n) : r.set(n, a);
  return r;
}
function T(e) {
  return e === "" || e === void 0 || e === null;
}
const ve = Y(null), de = $(function({ children: e, allFiltersSticky: t, onChange: r, onFilterSelectionChange: n, savedFiltersConfig: a }, v) {
  const [g, o] = K([]), [s, w] = K({}), [c, P] = K(
    {}
  ), { searchParams: y, updateURL: k } = st(), { savedFilterKey: O, getSavedFilters: te } = a || {}, q = xe(void 0), re = (i) => {
    const l = new URLSearchParams();
    return y.forEach((u, m) => {
      s[m] || l.append(m, u);
    }), ot(l, i);
  }, N = (i) => {
    const l = re(i);
    k(l, !0);
  }, x = (i) => {
    w(i), r == null || r(V(i));
  }, _ = ({
    filterKey: i,
    updatedFiltersOrder: l
  }) => {
    i ? o((u) => (n == null || n([...u, i]), [...u, i])) : l && (o(l), n == null || n(l));
  }, be = (i) => {
    I("Adding filter with key: %s", i), w((l) => ({
      ...l,
      [i]: C()
    })), r == null || r(
      V({
        ...s,
        [i]: C()
      })
    ), _({ filterKey: i });
  }, Re = (i) => {
    var l;
    I("Removing filter with key: %s", i);
    const u = (l = c[i]) == null ? void 0 : l.isSticky, m = {
      ...s,
      [i]: { ...C(), state: u ? S.VISIBLE : S.HIDDEN }
    }, f = g.filter((h) => u || h !== i);
    x(m), _({ updatedFiltersOrder: f });
    const d = D(f, m);
    I("Updating URL with query: %s", d), N(new URLSearchParams(d));
  }, Fe = (i, l, u) => {
    I("Updating filter: %s with value: %O", i, u);
    const m = { ...s, [i]: se(l, u) };
    x(m);
    const f = D(g, m);
    I("Updating URL with query: %s", f), N(new URLSearchParams(f));
  }, ne = async (i, l = !0) => {
    const u = await (te == null ? void 0 : te(i));
    if (!u)
      return;
    l && B(void 0, !1);
    const m = Object.keys(u).reduce(
      (f, d) => {
        var h;
        const p = (h = c[d]) == null ? void 0 : h.parser, E = u[d], b = p ? p.serialize(E) : E;
        return f[d] = se(b, E, !1), f;
      },
      {}
    );
    if (o((f) => {
      const d = Object.keys(m);
      return l ? d : [...f, ...d];
    }), w((f) => {
      const d = Object.keys(f).reduce(
        (h, p) => (h[p] = f[p], h[p].state !== S.FILTER_APPLIED && m[p] && (h[p] = m[p]), h),
        {}
      );
      return r == null || r(V(d)), d;
    }), O) {
      const f = new URLSearchParams(l ? "" : y);
      f.set(O, i), N(f);
    }
  }, Oe = (i) => {
    I("Adding initial filters: %O", s);
    const l = {}, u = {};
    for (const h in i) {
      const { defaultValue: p, parser: E, isSticky: b } = i[h], R = t ? !0 : b, U = p === void 0 ? p : E == null ? void 0 : E.serialize(p);
      let A = R ? S.VISIBLE : S.HIDDEN;
      T(U) || (A = S.FILTER_APPLIED), l[h] = {
        value: p,
        query: U,
        state: A
      }, u[h] = {
        defaultValue: p,
        parser: i[h].parser,
        isSticky: R
      };
    }
    y == null || y.forEach((h, p) => {
      var E;
      if (l[p]) {
        const b = (E = u == null ? void 0 : u[p]) == null ? void 0 : E.parser, R = b ? b.parse(h) : h;
        l[p] = {
          value: R,
          query: h,
          state: S.FILTER_APPLIED
        };
      }
    }), x(l), P(u), I("Initial filters added: %O", l), I("Initial filters config added: %O", u);
    const m = Object.keys(l).filter(
      (h) => l[h].state !== S.HIDDEN
    );
    _({ updatedFiltersOrder: m });
    const f = D(m, l);
    I("Updating URL with query: %s", f), f && N(new URLSearchParams(f)), q.current = l;
    const d = O ? y.get(O) : null;
    d && ne(d, !1);
  };
  J(() => {
    n == null || n(g);
  }, [g, n]), J(() => {
    if (!q.current) return;
    const i = D(g, s), l = Object.entries(s).reduce(
      (f, [d, h]) => {
        var p;
        return f[d] = h, y.has(d) || (f[d] = {
          ...C(),
          state: (p = c[d]) != null && p.isSticky ? S.VISIBLE : S.HIDDEN
        }), f;
      },
      {}
    );
    I("Syncing search params with filters: %s", i);
    const u = g.filter(
      (f) => {
        var d;
        return y.has(f) || ((d = c[f]) == null ? void 0 : d.isSticky);
      }
    );
    y.forEach((f, d) => {
      var h;
      if (s[d]) {
        const p = (h = c == null ? void 0 : c[d]) == null ? void 0 : h.parser, E = p ? p.parse(f) : f;
        l[d] = {
          value: E,
          query: f,
          state: S.FILTER_APPLIED
        }, u.includes(d) || u.push(d);
      }
    }, {});
    const m = D(u, l);
    i !== m && (x(l), _({ updatedFiltersOrder: u }));
  }, [y]);
  const C = () => ({
    value: void 0,
    query: void 0,
    state: S.VISIBLE
  }), se = (i, l, u = !0) => {
    const m = T(i);
    return {
      value: l,
      query: m ? void 0 : i,
      state: m ? S.VISIBLE : S.FILTER_APPLIED,
      persistInURL: u
    };
  }, V = (i) => {
    const l = i || s, u = Object.keys(l).length === 0 ? q.current : l;
    return Object.entries(u || {}).reduce((m, [f, d]) => (m[f] = d.value, m), {});
  }, B = (i, l = !0) => {
    const u = { ...s }, m = !i || (i == null ? void 0 : i.length) === 0;
    Object.keys(u).forEach((p) => {
      var E, b, R, U;
      const A = (E = c[p]) == null ? void 0 : E.isSticky, H = (b = c[p]) == null ? void 0 : b.defaultValue, ie = T(H) || (U = (R = c[p]) == null ? void 0 : R.parser) == null ? void 0 : U.serialize(H), ke = m || (i == null ? void 0 : i.includes(p));
      let ae = A ? S.VISIBLE : S.HIDDEN;
      T(ie) || (ae = S.FILTER_APPLIED), ke && (u[p] = {
        value: H,
        query: ie,
        state: ae
      });
    });
    const f = Object.keys(u).filter(
      (p) => u[p].state !== S.HIDDEN
    );
    x(u), _({ updatedFiltersOrder: f });
    const d = D(f, u);
    I("Updating URL with query: %s", d);
    const h = re(new URLSearchParams(d));
    l && O && h.delete(O), k(h, !0);
  };
  _e(v, () => ({
    // @ts-ignore
    getValues: V,
    reset: B
  }));
  const je = Object.keys(s).filter(
    (i) => s[i].state === S.HIDDEN
  ), De = (i) => {
    var l;
    return (l = s[i]) == null ? void 0 : l.value;
  };
  return /* @__PURE__ */ L.jsx(
    ve.Provider,
    {
      value: {
        visibleFilters: g,
        availableFilters: je,
        resetFilters: B,
        removeFilter: Re,
        getFilterValue: De,
        addFilter: be,
        updateFilter: Fe,
        applySavedFilter: ne,
        addInitialFilters: Oe
      },
      children: /* @__PURE__ */ L.jsx("div", { id: "filters", children: e })
    }
  );
}), Z = () => {
  const e = X(ve);
  if (!e)
    throw We("FiltersContext is missing. Ensure this is used within a FiltersProvider."), new Error("FiltersDropdown, FiltersRow, and Filter must be used within a FiltersAdapter.");
  return e;
}, lt = $(function({ view: e = "row", ...t }, r) {
  return e === "row" ? /* @__PURE__ */ L.jsx(de, { ...t, ref: r, allFiltersSticky: !0 }) : /* @__PURE__ */ L.jsx(de, { ...t, ref: r });
}), pt = () => {
  const e = $(function(t, r) {
    return /* @__PURE__ */ L.jsx(lt, { ref: r, ...t });
  });
  return e.Dropdown = function(t) {
    return /* @__PURE__ */ L.jsx(Qe, { ...t });
  }, e.Content = function(t) {
    return /* @__PURE__ */ L.jsx(Ze, { ...t });
  }, e.Component = function(t) {
    return /* @__PURE__ */ L.jsx(Xe, { ...t });
  }, e;
}, he = (e) => typeof e == "string" ? e : e.pathname || "/", Q = $(({ to: e, children: t, ...r }, n) => {
  const a = he(e);
  return /* @__PURE__ */ F("a", { href: a, ...r, ref: n, children: t });
});
Q.displayName = "LinkDefault";
const ee = $(
  ({ to: e, children: t, className: r, style: n, ...a }, v) => {
    const g = he(e), o = new URL(g, window.location.origin).pathname === window.location.pathname, s = typeof r == "function" ? r({ isActive: o, isPending: !1, isTransitioning: !1 }) : r, w = typeof n == "function" ? n({ isActive: o, isPending: !1, isTransitioning: !1 }) : n;
    return /* @__PURE__ */ F("a", { ref: v, href: g, className: s, style: w, ...a, children: t });
  }
);
ee.displayName = "NavLinkDefault";
const ct = ({ children: e }) => /* @__PURE__ */ F(G, { children: e }), ye = ({ children: e }) => {
  const t = window.location.pathname, r = $e.toArray(e);
  for (const n of r)
    if (Ne(n))
      if ("path" in n.props) {
        const a = n.props.path;
        if (!a) continue;
        if (!!n.props.exact ? t === a : t.includes(a)) return n;
      } else
        return n;
  return null;
}, me = ({ render: e, children: t, ...r }) => t ? /* @__PURE__ */ F(G, { children: t }) : e ? /* @__PURE__ */ F(G, { children: e(r) }) : null, we = (e) => {
  typeof e == "number" ? window.history.go(e) : window.location.href = e.toString();
}, Se = () => {
  const e = Ce;
  return [new URLSearchParams(), e];
}, Pe = () => [], Ee = () => ({}), Ie = { ...window.location, state: {}, key: "" }, Le = Y({
  Link: Q,
  NavLink: ee,
  Switch: ye,
  Route: me,
  location: Ie,
  navigate: we,
  useSearchParams: Se,
  useMatches: Pe,
  useParams: Ee
}), gt = () => {
  const { Outlet: e, ...t } = X(Le);
  return {
    ...t,
    isRouterVersion5: !e,
    Outlet: e ?? ct
  };
}, vt = ({
  children: e,
  Link: t = Q,
  NavLink: r = ee,
  Outlet: n,
  Switch: a = ye,
  Route: v = me,
  location: g = Ie,
  navigate: o = we,
  useSearchParams: s = Se,
  useMatches: w = Pe,
  useParams: c = Ee
}) => /* @__PURE__ */ F(
  Le.Provider,
  {
    value: {
      Link: t,
      NavLink: r,
      Outlet: n,
      Switch: a,
      Route: v,
      location: g,
      navigate: o,
      useSearchParams: s,
      useMatches: w,
      useParams: c
    },
    children: /* @__PURE__ */ F(nt, { location: g, navigate: o, children: e })
  }
);
export {
  dt as B,
  pt as G,
  vt as R,
  Z as Y,
  Ce as n,
  gt as u
};
//# sourceMappingURL=router-context-CDZd-F2n.js.map
