import { useCallback as C, useState as V, useEffect as I, useRef as _, useMemo as ce, useLayoutEffect as ie } from "react";
import { bi as R, H as ae } from "./use-page-data.BYLN5MSa.js";
var N, K;
function se() {
  if (K) return N;
  K = 1;
  var r = "Expected a function", e = NaN, o = "[object Symbol]", c = /^\s+|\s+$/g, f = /^[-+]0x[0-9a-f]+$/i, u = /^0b[01]+$/i, t = /^0o[0-7]+$/i, a = parseInt, v = typeof R == "object" && R && R.Object === Object && R, k = typeof self == "object" && self && self.Object === Object && self, D = v || k || Function("return this")(), T = Object.prototype, i = T.toString, l = Math.max, j = Math.min, w = function() {
    return D.Date.now();
  };
  function Z(n, d, m) {
    var E, L, M, S, g, b, p = 0, B = !1, O = !1, $ = !0;
    if (typeof n != "function")
      throw new TypeError(r);
    d = U(d) || 0, z(m) && (B = !!m.leading, O = "maxWait" in m, M = O ? l(U(m.maxWait) || 0, d) : M, $ = "trailing" in m ? !!m.trailing : $);
    function W(s) {
      var h = E, y = L;
      return E = L = void 0, p = s, S = n.apply(y, h), S;
    }
    function re(s) {
      return p = s, g = setTimeout(x, d), B ? W(s) : S;
    }
    function ne(s) {
      var h = s - b, y = s - p, P = d - h;
      return O ? j(P, M - y) : P;
    }
    function G(s) {
      var h = s - b, y = s - p;
      return b === void 0 || h >= d || h < 0 || O && y >= M;
    }
    function x() {
      var s = w();
      if (G(s))
        return J(s);
      g = setTimeout(x, ne(s));
    }
    function J(s) {
      return g = void 0, $ && E ? W(s) : (E = L = void 0, S);
    }
    function te() {
      g !== void 0 && clearTimeout(g), p = 0, E = b = L = g = void 0;
    }
    function oe() {
      return g === void 0 ? S : J(w());
    }
    function A() {
      var s = w(), h = G(s);
      if (E = arguments, L = this, b = s, h) {
        if (g === void 0)
          return re(b);
        if (O)
          return g = setTimeout(x, d), W(b);
      }
      return g === void 0 && (g = setTimeout(x, d)), S;
    }
    return A.cancel = te, A.flush = oe, A;
  }
  function z(n) {
    var d = typeof n;
    return !!n && (d == "object" || d == "function");
  }
  function q(n) {
    return !!n && typeof n == "object";
  }
  function ee(n) {
    return typeof n == "symbol" || q(n) && i.call(n) == o;
  }
  function U(n) {
    if (typeof n == "number")
      return n;
    if (ee(n))
      return e;
    if (z(n)) {
      var d = typeof n.valueOf == "function" ? n.valueOf() : n;
      n = z(d) ? d + "" : d;
    }
    if (typeof n != "string")
      return n === 0 ? n : +n;
    n = n.replace(c, "");
    var m = u.test(n);
    return m || t.test(n) ? a(n.slice(2), m ? 2 : 8) : f.test(n) ? e : +n;
  }
  return N = Z, N;
}
var ue = se();
const Q = /* @__PURE__ */ ae(ue);
var F = typeof window < "u" ? ie : I;
function Y(r, e, o, c) {
  const f = _(e);
  F(() => {
    f.current = e;
  }, [e]), I(() => {
    const u = window;
    if (!(u && u.addEventListener))
      return;
    const t = (a) => {
      f.current(a);
    };
    return u.addEventListener(r, t, c), () => {
      u.removeEventListener(r, t, c);
    };
  }, [r, o, c]);
}
function X(r) {
  const e = _(() => {
    throw new Error("Cannot call an event handler while rendering.");
  });
  return F(() => {
    e.current = r;
  }, [r]), C((...o) => {
    var c;
    return (c = e.current) == null ? void 0 : c.call(e, ...o);
  }, [e]);
}
var H = typeof window > "u";
function fe(r, e, o = {}) {
  const { initializeWithValue: c = !0 } = o, f = C(
    (i) => o.serializer ? o.serializer(i) : JSON.stringify(i),
    [o]
  ), u = C(
    (i) => {
      if (o.deserializer)
        return o.deserializer(i);
      if (i === "undefined")
        return;
      const l = e instanceof Function ? e() : e;
      let j;
      try {
        j = JSON.parse(i);
      } catch (w) {
        return console.error("Error parsing JSON:", w), l;
      }
      return j;
    },
    [o, e]
  ), t = C(() => {
    const i = e instanceof Function ? e() : e;
    if (H)
      return i;
    try {
      const l = window.localStorage.getItem(r);
      return l ? u(l) : i;
    } catch (l) {
      return console.warn(`Error reading localStorage key “${r}”:`, l), i;
    }
  }, [e, r, u]), [a, v] = V(() => c ? t() : e instanceof Function ? e() : e), k = X((i) => {
    H && console.warn(
      `Tried setting localStorage key “${r}” even though environment is not a client`
    );
    try {
      const l = i instanceof Function ? i(t()) : i;
      window.localStorage.setItem(r, f(l)), v(l), window.dispatchEvent(new StorageEvent("local-storage", { key: r }));
    } catch (l) {
      console.warn(`Error setting localStorage key “${r}”:`, l);
    }
  }), D = X(() => {
    H && console.warn(
      `Tried removing localStorage key “${r}” even though environment is not a client`
    );
    const i = e instanceof Function ? e() : e;
    window.localStorage.removeItem(r), v(i), window.dispatchEvent(new StorageEvent("local-storage", { key: r }));
  });
  I(() => {
    v(t());
  }, [r]);
  const T = C(
    (i) => {
      i.key && i.key !== r || v(t());
    },
    [r, t]
  );
  return Y("storage", T), Y("local-storage", T), [a, k, D];
}
var de = typeof window > "u";
function le(r, {
  defaultValue: e = !1,
  initializeWithValue: o = !0
} = {}) {
  const c = (a) => de ? e : window.matchMedia(a).matches, [f, u] = V(() => o ? c(r) : e);
  function t() {
    u(c(r));
  }
  return F(() => {
    const a = window.matchMedia(r);
    return t(), a.addListener ? a.addListener(t) : a.addEventListener("change", t), () => {
      a.removeListener ? a.removeListener(t) : a.removeEventListener("change", t);
    };
  }, [r]), f;
}
var ge = "(prefers-color-scheme: dark)", me = "usehooks-ts-dark-mode";
function Ee(r = {}) {
  const {
    defaultValue: e,
    localStorageKey: o = me,
    initializeWithValue: c = !0
  } = r, f = le(ge, {
    initializeWithValue: c,
    defaultValue: e
  }), [u, t] = fe(
    o,
    e ?? f ?? !1,
    { initializeWithValue: c }
  );
  return F(() => {
    f !== u && t(f);
  }, [f]), {
    isDarkMode: u,
    toggle: () => {
      t((a) => !a);
    },
    enable: () => {
      t(!0);
    },
    disable: () => {
      t(!1);
    },
    set: (a) => {
      t(a);
    }
  };
}
function he(r) {
  const e = _(r);
  e.current = r, I(
    () => () => {
      e.current();
    },
    []
  );
}
function Se(r, e = 500, o) {
  const c = _();
  he(() => {
    c.current && c.current.cancel();
  });
  const f = ce(() => {
    const u = Q(r, e, o), t = (...a) => u(...a);
    return t.cancel = () => {
      u.cancel();
    }, t.isPending = () => !!c.current, t.flush = () => u.flush(), t;
  }, [r, e, o]);
  return I(() => {
    c.current = Q(r, e, o);
  }, [r, e, o]), f;
}
export {
  fe as a,
  Se as b,
  le as c,
  Ee as u
};
