import "../../theme/accessibility.css.js";
import "../../theme/global.css.js";
import { backofficeDarkThemeClass as e, backofficeLightThemeClass as t } from "../../theme/theme.css.js";
import { cx as n } from "../../theme/tools.js";
import { adminDensityCompactClass as r } from "./adminDensity.css.js";
import { useEffect as i, useMemo as a, useState as o } from "react";
import { jsx as s } from "react/jsx-runtime";
//#region src/admin/theme/BackofficeThemeProvider.tsx
var c = "plumile-backoffice-theme-mode", l = () => typeof window > "u" || typeof window.matchMedia != "function" ? "light" : window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light", u = (e, t) => e === "system" ? t : e, d = (e) => e === "system" || e === "light" || e === "dark", f = (e) => {
	if (typeof window > "u") return e;
	let t = window.localStorage.getItem(c);
	return d(t) ? t : e;
}, p = ({ children: d, defaultMode: p = "system" }) => {
	let [m] = o(() => f(p)), [h, g] = o(() => l()), _ = u(m, h);
	return i(() => {
		if (m === "system" && typeof window < "u" && typeof window.matchMedia == "function") {
			let e = window.matchMedia("(prefers-color-scheme: dark)"), t = (t) => {
				if (t?.matches ?? e.matches) {
					g("dark");
					return;
				}
				g("light");
			};
			return t(e), e.addEventListener("change", t), () => {
				e.removeEventListener("change", t);
			};
		}
	}, [m]), i(() => {
		typeof window > "u" || window.localStorage.setItem(c, m);
	}, [m]), /* @__PURE__ */ s("div", {
		className: n(a(() => _ === "dark" ? e : t, [_]), r),
		children: d
	});
}, m = {
	getSystemTheme: l,
	isThemeMode: d,
	resolveTheme: u,
	readStoredMode: f
};
//#endregion
export { c as BACKOFFICE_THEME_MODE_KEY, p as BackofficeThemeProvider, p as default, m as __backofficeThemeTest };

//# sourceMappingURL=BackofficeThemeProvider.js.map