import { j as r } from "./_virtual/jsx-runtime.js";
import { forwardRef as I, useRef as d, useImperativeHandle as k, useEffect as j } 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@18.3.0-canary-3d9b20132-20240124_react@18.3.0-canary-3d_c02c1e17bf76c343fd22d1f22394ecf5/node_modules/react-hot-toast/dist/index.js";
import { tx as E } from "./packages/style-system/dist/twind.js";
import { useDarkMode as C } from "./node_modules/.pnpm/usehooks-ts@3.1.1_react@18.3.0-canary-3d9b20132-20240124/node_modules/usehooks-ts/dist/index.js";
import { createEditorStore as D, EditorStoreContext as R } from "./use-editor.js";
import { UploaderProvider as w } from "./packages/components/src/editor/components/UploaderContext.js";
/* empty css                                                                                                                                                                                     */
/* empty css                                     */
/* empty css                                    */
/* empty css                                            */
/* empty css                                              */
/* empty css                                                 */
import { createDraftStore as B, DraftStoreContext as L } from "./use-page-data.js";
import { Theme as M } from "./node_modules/.pnpm/@radix-ui_themes@3.1.4_@types_react-dom@18.3.6_@types_react@18.3.3__@types_react@18.3.3_46b1dabc193c5ff5696ee783983c694e/node_modules/@radix-ui/themes/dist/esm/components/theme.js";
const Q = I(
  ({
    config: m,
    pageVersion: c,
    pageId: l,
    onImageUpload: n,
    children: p,
    onSaveSite: f,
    onSavePage: u,
    onPublish: g,
    onShowPopup: h,
    onReady: v = () => {
    }
  }, x) => {
    const { site: e, pages: i } = m, t = new URL(self.location.href).searchParams, b = t.has("debug") && t.get("debug") !== "false", a = d(
      D({
        onPublish: g,
        onSaveSite: f,
        onSavePage: u,
        onShowPopup: h,
        logoLink: `/dashboard/sites/${e.id}`,
        debugMode: b,
        panel: t.get("panel") ?? void 0,
        selectedBrickId: t.get("selectedBrickId") ?? void 0,
        selectedSectionId: t.get("selectedBrickId") ? void 0 : t.get("selectedSectionId") ?? void 0,
        modal: t.get("modal") ?? void 0,
        panelPosition: t.get("panelPosition") ?? void 0,
        sitePrompt: e.sitePrompt
      })
    ).current, o = i.find((P) => P.id === l) ?? i[0], s = d(
      B({
        siteId: e.id,
        hostname: e.hostname,
        sitemap: e.sitemap,
        siteLabel: e.label,
        id: o.id,
        version: c,
        path: o.path,
        label: o.label,
        sections: o.sections,
        pageAttributes: o.attributes,
        siteAttributes: e.attributes,
        datasources: e.datasources,
        datarecords: e.datarecords,
        pages: i,
        // todo: pass the appropriate data for the page
        data: {},
        theme: e.theme
      })
    ).current;
    k(
      x,
      () => ({
        editorStore: a,
        draftStore: s
      }),
      [a, s]
    );
    const { isDarkMode: S } = C();
    return j(v, []), /* @__PURE__ */ r.jsx(w, { onImageUpload: n, children: /* @__PURE__ */ r.jsx(R.Provider, { value: a, children: /* @__PURE__ */ r.jsx(L.Provider, { value: s, children: /* @__PURE__ */ r.jsx(
      M,
      {
        accentColor: "violet",
        className: E("w-full flex flex-col"),
        appearance: S ? "dark" : "light",
        children: p
      }
    ) }, "DraftStoreContext") }, "EditorStoreContext") });
  }
);
export {
  Q as EditorWrapper
};
//# sourceMappingURL=EditorWrapper.js.map
