import { createContext as e, useContext as t, useEffect as n, useState as r } from "react";
import { jsx as i } from "react/jsx-runtime";
//#region src/components/theme-provider.tsx
var a = e({
	theme: "system",
	setTheme: () => null
});
function o({ children: e, defaultTheme: t = "system", storageKey: o = "vite-ui-theme", ...s }) {
	let [c, l] = r(() => localStorage.getItem(o) || t);
	n(() => {
		let e = window.document.documentElement;
		if (e.classList.remove("light", "dark"), c === "system") {
			let t = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
			e.classList.add(t);
			return;
		}
		e.classList.add(c);
	}, [c]);
	let u = {
		theme: c,
		setTheme: (e) => {
			localStorage.setItem(o, e), l(e);
		}
	};
	return /* @__PURE__ */ i(a.Provider, {
		...s,
		value: u,
		children: e
	});
}
var s = () => {
	let e = t(a);
	if (e === void 0) throw Error("useTheme must be used within a ThemeProvider");
	return e;
};
//#endregion
export { s as n, o as t };
