import { jsx } from "react/jsx-runtime";
import { forwardRef, useRef, useImperativeHandle, useEffect } from "react";
import "./chunks/index.W70dzubm.js";
import { a as tx } from "./chunks/twind.DdSZmZu6.js";
import { u as useDarkMode } from "./chunks/index.Dcu_6uM0.js";
import { g as createEditorStore, E as EditorStoreContext } from "./chunks/use-editor.BTqnSFNX.js";
import { U as UploaderProvider } from "./chunks/UploaderContext.DwS2olmD.js";
import { w as createDraftStore, D as DraftStoreContext } from "./chunks/use-page-data.BgY0vKG4.js";
import { R } from "./chunks/theme.BUf-nmmj.js";
const EditorWrapper = forwardRef(
  ({
    chatSession,
    site,
    pages,
    pageVersion,
    pageId,
    onImageUpload,
    children,
    onSaveSite,
    onSavePage,
    onShowPopup,
    onPageCreated,
    onReady = () => {
    }
  }, ref) => {
    const urlParams = new URL(self.location.href).searchParams;
    const debugMode = urlParams.has("debug") && urlParams.get("debug") !== "false";
    const editorStore = useRef(
      createEditorStore({
        onSaveSite,
        onSavePage,
        onShowPopup,
        onPageCreated,
        logoLink: `/dashboard/sites/${site.id}`,
        debugMode,
        chatSession,
        panel: urlParams.get("panel") ?? void 0,
        selectedBrickId: urlParams.get("selectedBrickId") ?? void 0,
        selectedSectionId: urlParams.get("selectedBrickId") ? void 0 : urlParams.get("selectedSectionId") ?? void 0,
        modal: urlParams.get("modal") ?? void 0,
        attributesTab: urlParams.get("attributesTab") ?? void 0,
        panelPosition: urlParams.get("panelPosition") ?? void 0
      })
    ).current;
    const draftStore = useRef(
      createDraftStore({
        site,
        page: {
          ...pages[0],
          version: pageVersion
        }
      })
    ).current;
    useImperativeHandle(
      ref,
      () => ({
        editorStore,
        draftStore
      }),
      [editorStore, draftStore]
    );
    const { isDarkMode } = useDarkMode();
    useEffect(onReady, []);
    return /* @__PURE__ */ jsx(UploaderProvider, { onImageUpload, children: /* @__PURE__ */ jsx(EditorStoreContext.Provider, { value: editorStore, children: /* @__PURE__ */ jsx(DraftStoreContext.Provider, { value: draftStore, children: /* @__PURE__ */ jsx(
      R,
      {
        accentColor: "violet",
        className: tx("w-full flex flex-col"),
        appearance: isDarkMode ? "dark" : "light",
        children
      }
    ) }, "DraftStoreContext") }, "EditorStoreContext") });
  }
);
export {
  EditorWrapper
};
//# sourceMappingURL=EditorWrapper.js.map
