import { createContext, useCallback, useContext, useEffect, useState } from "react";
import { jsx, jsxs } from "react/jsx-runtime";
//#region editors/shared/theme-context.tsx
const STORAGE_KEY = "bai-theme";
const ThemeContext = createContext({
	theme: "dark",
	toggle: () => {}
});
function getStoredTheme() {
	try {
		const stored = localStorage.getItem(STORAGE_KEY);
		if (stored === "light" || stored === "dark") return stored;
	} catch {}
	return "dark";
}
function ThemeProvider({ children }) {
	const [theme, setTheme] = useState(getStoredTheme);
	useEffect(() => {
		try {
			localStorage.setItem(STORAGE_KEY, theme);
		} catch {}
	}, [theme]);
	const toggle = useCallback(() => {
		setTheme((t) => t === "dark" ? "light" : "dark");
	}, []);
	return /* @__PURE__ */ jsx(ThemeContext.Provider, {
		value: {
			theme,
			toggle
		},
		children: /* @__PURE__ */ jsx("div", {
			"data-bai-theme": theme,
			className: "bai-theme",
			children
		})
	});
}
function useTheme() {
	return useContext(ThemeContext);
}
/** Same classes — CSS vars resolve differently under each theme */
const TOOLBAR_CLASS = [
	"!bg-[var(--bai-surface)] !border-[var(--bai-border)]",
	"[&_button]:!bg-[var(--bai-bg)] [&_button]:!border-[var(--bai-border)]",
	"[&_button:hover]:!bg-[var(--bai-hover)]",
	"[&_button_svg]:!text-[var(--bai-text-tertiary)] [&_button:hover_svg]:!text-[var(--bai-text-secondary)]",
	"[&_span]:!text-[var(--bai-text-tertiary)] [&_button:hover_span]:!text-[var(--bai-text-secondary)]",
	"[&_h1]:!text-[var(--bai-text-tertiary)]"
].join(" ");
/** Small sun/moon toggle button */
function ThemeToggle() {
	const { theme, toggle } = useTheme();
	return /* @__PURE__ */ jsx("button", {
		type: "button",
		onClick: toggle,
		className: "flex h-7 w-7 items-center justify-center rounded-md transition-colors",
		style: {
			background: "var(--bai-hover)",
			color: "var(--bai-text-tertiary)"
		},
		title: `Switch to ${theme === "dark" ? "light" : "dark"} mode`,
		children: theme === "dark" ? /* @__PURE__ */ jsxs("svg", {
			className: "h-3.5 w-3.5",
			viewBox: "0 0 24 24",
			fill: "none",
			stroke: "currentColor",
			strokeWidth: "2",
			children: [/* @__PURE__ */ jsx("circle", {
				cx: "12",
				cy: "12",
				r: "5"
			}), /* @__PURE__ */ jsx("path", { d: "M12 1v2M12 21v2M4.22 4.22l1.42 1.42M18.36 18.36l1.42 1.42M1 12h2M21 12h2M4.22 19.78l1.42-1.42M18.36 5.64l1.42-1.42" })]
		}) : /* @__PURE__ */ jsx("svg", {
			className: "h-3.5 w-3.5",
			viewBox: "0 0 24 24",
			fill: "none",
			stroke: "currentColor",
			strokeWidth: "2",
			children: /* @__PURE__ */ jsx("path", { d: "M21 12.79A9 9 0 1111.21 3 7 7 0 0021 12.79z" })
		})
	});
}
//#endregion
export { ThemeProvider as n, ThemeToggle as r, TOOLBAR_CLASS as t };

//# sourceMappingURL=theme-context-DeP5ztQx.mjs.map