import { ref as m, computed as h, watch as l, unref as s, onMounted as u, onUnmounted as c } from "vue";
import { toList as w, mapIterable as f } from "../helpers/iterators.js";
import { useLocalStorage as v } from "./useLocalStorage.js";
const r = /* @__PURE__ */ new Set();
window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => {
  w(f(r.values(), (t) => t(e.matches ? "dark" : "light")));
});
const g = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light", d = m(g), o = v("theme");
function T(e) {
  const t = h(() => o.value ? o.value : d.value), n = (a) => {
    d.value = a, e == null || e(a);
  };
  function i() {
    o.value = t.value === "light" ? "dark" : (t.value === "dark", "light");
  }
  return l(t, (a) => {
    e == null || e(s(a));
  }), u(() => {
    r.add(n);
  }), c(() => {
    r.delete(n);
  }), [t, i];
}
export {
  T as useTheme
};
//# sourceMappingURL=useTheme.js.map
