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.Bxix3KXR.js";
import { _ as C } from "./chunks/twind.D7be0E5m.js";
import { a as R } from "./chunks/index.BJ4j-pYz.js";
import { DatasourceProvider as U } from "./use-datasource.js";
import { v as k, w as I, E as L, D as M } from "./chunks/use-editor.BDnIlF7c.js";
import { U as j } from "./chunks/UploaderContext.3cbhDliz.js";
import { I as A } from "./chunks/theme.BGpzuiJ2.js";
const F = w(
  ({
    config: d,
    pageVersion: n,
    pageId: c,
    mode: l,
    onImageUpload: m,
    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(
      k({
        mode: l,
        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((g) => g.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;
    D(
      S,
      () => ({
        editorStore: o,
        draftStore: s
      }),
      [o, s]
    );
    const { isDarkMode: P } = R();
    return E(v, []), /* @__PURE__ */ r(U, { children: /* @__PURE__ */ r(j, { onImageUpload: m, children: /* @__PURE__ */ r(L.Provider, { value: o, children: /* @__PURE__ */ r(M.Provider, { value: s, children: /* @__PURE__ */ r(
      A,
      {
        accentColor: "violet",
        className: C("w-full flex flex-col"),
        appearance: P ? "dark" : "light",
        children: p
      }
    ) }, "DraftStoreContext") }, "EditorStoreContext") }) });
  }
);
export {
  F as EditorWrapper
};
//# sourceMappingURL=EditorWrapper.js.map
