import { j as jsxRuntimeExports } from "./_virtual/jsx-runtime.js";
import { forwardRef, useRef, useImperativeHandle, useEffect } from "react";
import "./node_modules/.pnpm/@formkit_auto-animate@0.8.2/node_modules/@formkit/auto-animate/index.js";
import "./node_modules/.pnpm/react-hot-toast@2.5.2_react-dom@19.1.1_react@19.1.1__react@19.1.1/node_modules/react-hot-toast/dist/index.js";
import { tx as D } from "./packages/style-system/dist/twind.js";
import { useDarkMode } from "./node_modules/.pnpm/usehooks-ts@3.1.1_react@19.1.1/node_modules/usehooks-ts/dist/index.js";
import { createEditorStore, EditorStoreContext } from "./use-editor.js";
import { UploaderProvider } from "./packages/components/src/editor/components/UploaderContext.js";
/* empty css                                                                                                                                                                                     */
/* empty css                                     */
/* empty css                                    */
/* empty css                                            */
/* empty css                                              */
/* empty css                                                 */
import { createDraftStore, DraftStoreContext } from "./use-page-data.js";
import { Theme as R } from "./node_modules/.pnpm/@radix-ui_themes@3.2.1_@types_react-dom@19.1.9_@types_react@19.1.13__@types_react@19.1._832fa1fef691e6e9510ada03948dc85c/node_modules/@radix-ui/themes/dist/esm/components/theme.js";
const EditorWrapper = forwardRef(
  ({
    config,
    pageVersion,
    pageId,
    onImageUpload,
    children,
    onSaveSite,
    onSavePage,
    onPublish,
    onShowPopup,
    onReady = () => {
    }
  }, ref) => {
    const { site, pages } = config;
    const urlParams = new URL(self.location.href).searchParams;
    const debugMode = urlParams.has("debug") && urlParams.get("debug") !== "false";
    const editorStore = useRef(
      createEditorStore({
        onPublish,
        onSaveSite,
        onSavePage,
        onShowPopup,
        logoLink: `/dashboard/sites/${site.id}`,
        debugMode,
        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 page = pages.find((p) => p.id === pageId) ?? pages[0];
    const draftStore = useRef(
      createDraftStore({
        site,
        page: {
          ...page,
          version: pageVersion
        }
      })
    ).current;
    useImperativeHandle(
      ref,
      () => ({
        editorStore,
        draftStore
      }),
      [editorStore, draftStore]
    );
    const { isDarkMode } = useDarkMode();
    useEffect(onReady, []);
    return /* @__PURE__ */ jsxRuntimeExports.jsx(UploaderProvider, { onImageUpload, children: /* @__PURE__ */ jsxRuntimeExports.jsx(EditorStoreContext.Provider, { value: editorStore, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DraftStoreContext.Provider, { value: draftStore, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
      R,
      {
        accentColor: "violet",
        className: D("w-full flex flex-col"),
        appearance: isDarkMode ? "dark" : "light",
        children
      }
    ) }, "DraftStoreContext") }, "EditorStoreContext") });
  }
);
export {
  EditorWrapper
};
//# sourceMappingURL=EditorWrapper.js.map
