import { jsx as r } from "react/jsx-runtime";
import { forwardRef as P, useRef as i, useImperativeHandle as w, useEffect as D } from "react";
import { g as E } from "./chunks/index.B-GbFHzr.js";
import { _ as C } from "./chunks/twind.D_WBdNpx.js";
import { i as R, E as U } from "./chunks/use-editor.BioV43yU.js";
import { U as k } from "./chunks/UploaderContext.3cbhDliz.js";
import { m as I, D as L } from "./chunks/use-page-data.ClF2QKbJ.js";
import { I as M } from "./chunks/theme.DuOtkXia.js";
const y = P(
  ({
    config: d,
    pageVersion: n,
    pageId: c,
    onImageUpload: m,
    children: l,
    onSaveSite: p,
    onSavePage: f,
    onPublish: u,
    onShowPopup: h,
    onReady: b = () => {
    }
  }, v) => {
    const { site: t, pages: a } = d, S = new URLSearchParams(window.location.search).has("debug"), o = i(
      R({
        onPublish: u,
        onSaveSite: p,
        onSavePage: f,
        onShowPopup: h,
        debugMode: S,
        panel: new URL(self.location.href).searchParams.get("panel") ?? void 0,
        sitePrompt: t.sitePrompt
      })
    ).current, e = a.find((x) => x.id === c) ?? a[0], s = i(
      I({
        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;
    w(
      v,
      () => ({
        editorStore: o,
        draftStore: s
      }),
      [o, s]
    );
    const { isDarkMode: g } = E();
    return D(b, []), /* @__PURE__ */ r(k, { onImageUpload: m, children: /* @__PURE__ */ r(U.Provider, { value: o, children: /* @__PURE__ */ r(L.Provider, { value: s, children: /* @__PURE__ */ r(
      M,
      {
        accentColor: "violet",
        className: C("w-full flex flex-col"),
        appearance: g ? "dark" : "light",
        children: l
      }
    ) }, "DraftStoreContext") }, "EditorStoreContext") });
  }
);
export {
  y as EditorWrapper
};
//# sourceMappingURL=EditorWrapper.js.map
