import "./accessibility.css.js";
import "./global.css.js";
import { publicDarkThemeClass as e, publicLightThemeClass as t } from "./theme.css.js";
import { createContext as n, useContext as r, useEffect as i, useMemo as a, useState as o } from "react";
import { jsx as s } from "react/jsx-runtime";
//#region src/theme/ThemeProvider.tsx
var c = n(void 0), l = "plumile-theme-mode", u = () => typeof window > "u" || typeof window.matchMedia != "function" ? "light" : window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light", d = (e, t) => e === "system" ? t : e, f = (e) => e === "system" || e === "light" || e === "dark", p = (e, t = l) => {
	if (typeof window > "u") return e;
	let n = window.localStorage.getItem(t);
	return f(n) ? n : e;
}, m = (e) => e.split(/\s+/).filter(Boolean), h = ({ children: n, defaultMode: r = "system" }) => {
	let [f, h] = o(() => p(r)), [g, _] = o(() => u()), v = d(f, g);
	i(() => {
		if (f === "system" && typeof window < "u" && typeof window.matchMedia == "function") {
			let e = window.matchMedia("(prefers-color-scheme: dark)"), t = (t) => {
				if (t?.matches ?? e.matches) {
					_("dark");
					return;
				}
				_("light");
			};
			return t(e), e.addEventListener("change", t), () => {
				e.removeEventListener("change", t);
			};
		}
	}, [f]), i(() => {
		typeof window > "u" || window.localStorage.setItem(l, f);
	}, [f]), i(() => {
		if (typeof document > "u") return;
		let n = document.body, r = t;
		return v === "dark" && (r = e), n.classList.remove(...m(t), ...m(e)), n.classList.add(...m(r)), () => {
			n.classList.remove(...m(t), ...m(e));
		};
	}, [v]);
	let y = a(() => ({
		mode: f,
		resolvedTheme: v,
		setMode: h
	}), [f, v]);
	return /* @__PURE__ */ s(c.Provider, {
		value: y,
		children: n
	});
}, g = () => {
	let e = r(c);
	if (e == null) throw Error("useTheme must be used within a ThemeProvider");
	return e;
}, _ = {
	getSystemTheme: u,
	isThemeMode: f,
	resolveTheme: d,
	readStoredMode: p,
	splitClassName: m
};
//#endregion
export { l as THEME_MODE_KEY, h as ThemeProvider, _ as __test, g as useTheme };

//# sourceMappingURL=ThemeProvider.js.map