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