import { jsx as t } from "react/jsx-runtime";
import { forwardRef as g, useRef as i, useImperativeHandle as S, useEffect as x } from "react";
import "./chunks/index.D1n9HtNk.js";
import { a as b } from "./chunks/twind.Cg2g8xBZ.js";
import { u as h } from "./chunks/index.CbebiNuJ.js";
import { g as k, E as P } from "./chunks/use-editor.CLs27I-R.js";
import { U as D } from "./chunks/UploaderContext.3cbhDliz.js";
import { v as E, D as I } from "./chunks/use-page-data.BYLN5MSa.js";
import { R as C } from "./chunks/theme.BwnlJUJD.js";
const N = g(
  ({
    chatSession: d,
    site: a,
    pages: s,
    // pageVersion,
    // pageId,
    onImageUpload: l,
    children: c,
    onSaveSite: n,
    onShowPopup: f,
    onReady: m = () => {
    }
  }, p) => {
    const e = new URL(self.location.href).searchParams, u = e.has("debug") && e.get("debug") !== "false", r = i(
      k({
        onSaveSite: n,
        onShowPopup: f,
        logoLink: `/dashboard/sites/${a.id}`,
        debugMode: u,
        chatSession: d,
        panel: e.get("panel") ?? void 0,
        selectedBrickId: e.get("selectedBrickId") ?? void 0,
        selectedSectionId: e.get("selectedBrickId") ? void 0 : e.get("selectedSectionId") ?? void 0,
        modal: e.get("modal") ?? void 0,
        attributesTab: e.get("attributesTab") ?? void 0,
        panelPosition: e.get("panelPosition") ?? void 0
      })
    ).current, o = i(
      E({
        site: a,
        page: {
          ...s[0],
          version: "latest"
          // version: pageVersion,
        }
      })
    ).current;
    S(
      p,
      () => ({
        editorStore: r,
        draftStore: o
      }),
      [r, o]
    );
    const { isDarkMode: v } = h();
    return x(m, []), /* @__PURE__ */ t(D, { onImageUpload: l, children: /* @__PURE__ */ t(P.Provider, { value: r, children: /* @__PURE__ */ t(I.Provider, { value: o, children: /* @__PURE__ */ t(
      C,
      {
        accentColor: "violet",
        className: b("w-full flex flex-col"),
        appearance: v ? "dark" : "light",
        children: c
      }
    ) }, "DraftStoreContext") }, "EditorStoreContext") });
  }
);
export {
  N as EditorWrapper
};
