import { h as e } from "./chunks/chunk.BlbRoQQ3.js";
import { b as t, c as n } from "./chunks/use-editor.C-_8sOOa.js";
import { b as r, c as i } from "./chunks/use-page-data.Cb2SuuwJ.js";
import "./chunks/chunk-LSPN22SI.D75E3zS-.js";
import { c as a } from "./chunks/twind.BiM9xcCd.js";
import "./chunks/system.DbMQd1I1.js";
import { b as o } from "./chunks/jsx-runtime.DF4K5VCp.js";
import { c as s } from "./chunks/theme.HtT_2QlC.js";
import { b as c } from "./chunks/dist.ccQGo6gv.js";
import { b as l } from "./chunks/UploaderContext.BQZH1D99.js";
import { forwardRef as u, useEffect as d, useImperativeHandle as f, useRef as p } from "react";
var m = /* @__PURE__ */ e(o());
const h = u(({ config: e, pageVersion: o, pageId: u, onImageUpload: h, children: g, onSaveSite: _, onSavePage: v, onPublish: y, onShowPopup: b, onReady: x = () => {} }, S) => {
	let { site: C, pages: w } = e, T = new URL(self.location.href).searchParams, E = T.has("debug") && T.get("debug") !== "false", D = p(n({
		onPublish: y,
		onSaveSite: _,
		onSavePage: v,
		onShowPopup: b,
		debugMode: E,
		panel: T.get("panel") ?? void 0,
		selectedBrickId: T.get("selectedBrickId") ?? void 0,
		selectedSectionId: T.get("selectedBrickId") ? void 0 : T.get("selectedSectionId") ?? void 0,
		modal: T.get("modal") ?? void 0,
		panelPosition: T.get("panelPosition") ?? void 0,
		sitePrompt: C.sitePrompt
	})).current, O = w.find((e) => e.id === u) ?? w[0], k = p(i({
		siteId: C.id,
		hostname: C.hostname,
		sitemap: C.sitemap,
		siteLabel: C.label,
		id: O.id,
		version: o,
		path: O.path,
		label: O.label,
		sections: O.sections,
		pageAttributes: O.attributes,
		siteAttributes: C.attributes,
		datasources: C.datasources,
		datarecords: C.datarecords,
		pages: w,
		data: {},
		theme: C.theme
	})).current;
	f(S, () => ({
		editorStore: D,
		draftStore: k
	}), [D, k]);
	let { isDarkMode: A } = c();
	return d(x, []), /* @__PURE__ */ (0, m.jsx)(l, {
		onImageUpload: h,
		children: /* @__PURE__ */ (0, m.jsx)(t.Provider, {
			value: D,
			children: /* @__PURE__ */ (0, m.jsx)(r.Provider, {
				value: k,
				children: /* @__PURE__ */ (0, m.jsx)(s, {
					accentColor: "violet",
					className: a("w-full flex flex-col"),
					appearance: A ? "dark" : "light",
					children: g
				})
			}, "DraftStoreContext")
		}, "EditorStoreContext")
	});
});
export { h as EditorWrapper };

//# sourceMappingURL=EditorWrapper.js.map