import { bootstrapTheme as e, getTheme as t, setThemePartial as n } from "../services/theme-engine/index.js";
import { renderThemeStudio as r } from "../components/theme/theme-studio.js";
import { useEffect as i, useRef as a } from "react";
import { jsx as o } from "react/jsx-runtime";
//#region src/react/theme-studio.tsx
function s() {
	try {
		return typeof localStorage < "u" && localStorage.getItem("cm-theme-v1") !== null;
	} catch {
		return !1;
	}
}
function c(e, t) {
	return !e || t === "never" ? !1 : t === "always" ? !0 : !s();
}
function l(e) {
	return e instanceof CustomEvent && e.detail ? e.detail : t();
}
function u({ className: s, initialTheme: u, onThemeChange: d, seedStrategy: f = "if-empty", showTabs: p, showHeader: m, showBrandSection: h }) {
	let g = a(null), _ = a(d), v = a(!1);
	return i(() => {
		_.current = d;
	}, [d]), i(() => {
		if (typeof document > "u") return;
		let r = (e) => {
			_.current?.(l(e));
		};
		return document.addEventListener("cm:theme-change", r), v.current || (v.current = !0, c(u, f) && n(u)), e(), r(new CustomEvent("cm:theme-change", { detail: t() })), () => {
			document.removeEventListener("cm:theme-change", r);
		};
	}, [u, f]), i(() => {
		let e = g.current;
		if (!e) return;
		let t = {};
		return p !== void 0 && (t.showTabs = p), m !== void 0 && (t.showHeader = m), h !== void 0 && (t.showBrandSection = h), r(e, t), () => {
			e.replaceChildren();
		};
	}, [
		p,
		m,
		h
	]), /* @__PURE__ */ o("div", {
		ref: g,
		"data-slot": "theme-studio",
		className: ["cmm-theme-studio-react", s].filter(Boolean).join(" ")
	});
}
u.displayName = "ThemeStudio";
//#endregion
export { u as ThemeStudio };

//# sourceMappingURL=theme-studio.js.map