import { jsx as r } from "react/jsx-runtime";
import { forwardRef as w, useRef as i, useImperativeHandle as D, useEffect as E } from "react";
import "./chunks/index.D1WHzYVh.js";
import { _ as C } from "./chunks/twind.D7be0E5m.js";
import { a as R } from "./chunks/index.CQJkC40r.js";
import { i as U, E as k } from "./chunks/use-editor.BDXlYRYz.js";
import { U as I } from "./chunks/UploaderContext.3cbhDliz.js";
import { m as L, D as M } from "./chunks/use-page-data.BTws06Go.js";
import { I as j } from "./chunks/theme.DDkAXowQ.js";
const B = w(
  ({
    config: d,
    pageVersion: n,
    pageId: c,
    mode: m,
    onImageUpload: l,
    children: p,
    onSaveSite: f,
    onSavePage: u,
    onPublish: h,
    onShowPopup: b,
    onReady: v = () => {
    }
  }, S) => {
    const { site: t, pages: a } = d, x = new URLSearchParams(window.location.search).has("debug"), o = i(
      U({
        mode: m,
        onPublish: h,
        onSaveSite: f,
        onSavePage: u,
        onShowPopup: b,
        debugMode: x,
        panel: new URL(self.location.href).searchParams.get("panel") ?? void 0,
        sitePrompt: t.sitePrompt
      })
    ).current, e = a.find((P) => P.id === c) ?? a[0], s = i(
      L({
        siteId: t.id,
        hostname: t.hostname,
        sitemap: t.sitemap,
        siteLabel: t.label,
        id: e.id,
        version: n,
        path: e.path,
        label: e.label,
        sections: e.sections,
        siteAttr: t.attr,
        attr: Object.assign({}, t.attr, e.attr),
        attributes: e.attributes,
        siteAttributes: t.attributes,
        datasources: t.datasources,
        datarecords: t.datarecords,
        pages: a,
        // todo: pass the appropriate data for the page
        data: {},
        theme: t.theme
      })
    ).current;
    D(
      S,
      () => ({
        editorStore: o,
        draftStore: s
      }),
      [o, s]
    );
    const { isDarkMode: g } = R();
    return E(v, []), /* @__PURE__ */ r(I, { onImageUpload: l, children: /* @__PURE__ */ r(k.Provider, { value: o, children: /* @__PURE__ */ r(M.Provider, { value: s, children: /* @__PURE__ */ r(
      j,
      {
        accentColor: "violet",
        className: C("w-full flex flex-col"),
        appearance: g ? "dark" : "light",
        children: p
      }
    ) }, "DraftStoreContext") }, "EditorStoreContext") });
  }
);
export {
  B as EditorWrapper
};
//# sourceMappingURL=EditorWrapper.js.map
