import { ref as s, watch as u } from "vue";
const t = s(!1);
function c(r) {
  var n;
  const a = () => {
    var o, i;
    const e = typeof window < "u" ? (o = window.localStorage) == null ? void 0 : o.getItem("isDark") : null;
    return typeof e == "string" ? !!JSON.parse(e) : !!(typeof window < "u" && ((i = window == null ? void 0 : window.matchMedia("(prefers-color-scheme: dark)")) != null && i.matches));
  }, d = () => {
    var e;
    t.value = !t.value, typeof window < "u" && ((e = window == null ? void 0 : window.localStorage) == null || e.setItem("isDark", JSON.stringify(t.value)));
  };
  function l(e) {
    var o;
    t.value = e, typeof window < "u" && ((o = window == null ? void 0 : window.localStorage) == null || o.setItem("isDark", JSON.stringify(t.value)));
  }
  return t.value = (typeof window > "u" ? null : JSON.parse(((n = window.localStorage) == null ? void 0 : n.getItem("isDark")) || "null")) ?? r ?? a(), u(
    t,
    (e) => {
      typeof document > "u" || (document.body.classList.toggle("dark-mode", e), document.body.classList.toggle("light-mode", !e));
    },
    { immediate: !0 }
  ), {
    isDark: t,
    toggleDarkMode: d,
    setDarkMode: l
  };
}
export {
  c as useDarkModeState
};
