import { jsx as d } from "react/jsx-runtime";
import { useState as h, useEffect as i, useMemo as l } from "react";
import u from "../theme-context/themeContext.js";
const g = ({ defaultTheme: r, storageKey: t = "jtl-ui-theme", children: s }) => {
  const [e, c] = h(() => r ?? localStorage.getItem(t) ?? "system");
  i(() => {
    localStorage.setItem(t, e);
    const m = window.matchMedia("(prefers-color-scheme: dark)");
    document.documentElement.dataset.colorScheme = e === "system" ? m.matches ? "dark" : "light" : e;
    const o = (n) => {
      e === "system" && (document.documentElement.dataset.colorScheme = n.matches ? "dark" : "light");
    };
    return m.addEventListener("change", o), () => {
      m.removeEventListener("change", o);
    };
  }, [e, t]);
  const a = l(
    () => ({
      theme: e,
      setTheme: c
    }),
    [e]
  );
  return /* @__PURE__ */ d(u.Provider, { value: a, children: s });
};
export {
  g as default
};
//# sourceMappingURL=ThemeProvider.js.map
