import { LAYOUT_ROW_HEIGHT as g } from "./packages/sdk/dist/shared/layout-constants.js";
import { a } from "./packages/sdk/dist/shared/chunk-RDZK73KV.js";
import { enableMapSet as p } from "./node_modules/.pnpm/immer@10.1.1/node_modules/immer/dist/immer.js";
import { isEqual as m, isNil as b } from "lodash-es";
import { createContext as S, useContext as x } from "react";
import { temporal as h } from "./node_modules/.pnpm/zundo@2.3.0_zustand@4.5.5_@types_react@18.3.3_immer@10.1.1_react@18.3.0-canary-3d9b20132-20240124_/node_modules/zundo/dist/index.js";
import { useStore as r } from "./node_modules/.pnpm/zustand@4.5.5_@types_react@18.3.3_immer@10.1.1_react@18.3.0-canary-3d9b20132-20240124/node_modules/zustand/esm/index.js";
import { subscribeWithSelector as P } from "./node_modules/.pnpm/zustand@4.5.5_@types_react@18.3.3_immer@10.1.1_react@18.3.0-canary-3d9b20132-20240124/node_modules/zustand/esm/middleware.js";
import { immer as f } from "./node_modules/.pnpm/zustand@4.5.5_@types_react@18.3.3_immer@10.1.1_react@18.3.0-canary-3d9b20132-20240124/node_modules/zustand/esm/middleware/immer.js";
import { usePageContext as I } from "./use-page-data.js";
import { createStore as M } from "./node_modules/.pnpm/zustand@4.5.5_@types_react@18.3.3_immer@10.1.1_react@18.3.0-canary-3d9b20132-20240124/node_modules/zustand/esm/vanilla.js";
p();
const O = (i) => {
  const o = {
    previewMode: "desktop",
    themesLibrary: [],
    panelPosition: "left",
    logoLink: "/dashboard",
    zoom: 1,
    chatVisible: !0,
    contextMenuVisible: !1,
    planIndex: 0,
    imagesSearchResults: void 0,
    onPublish: () => {
      console.warn("onPublish is not implemented");
    },
    onDraftChange: async () => {
      console.warn("onDraftChange is not implemented");
    },
    debugMode: !1
  };
  return M()(
    P(
      h(
        f((n, c) => ({
          ...o,
          ...i,
          updateHistory: () => {
            setTimeout(() => {
              const e = c(), t = {
                panel: e.panel,
                selectedBrickId: e.selectedBrickId,
                selectedSectionId: e.selectedBrickId ? void 0 : e.selectedSectionId,
                panelPosition: e.panelPosition,
                attributesTab: e.attributesTab,
                modal: e.modal,
                debug: void 0
              }, d = new URL(window.location.href);
              Object.entries(t).forEach(([u, l]) => {
                !b(l) && l.toString().trim() !== "" ? d.searchParams.set(u, l.toString()) : d.searchParams.delete(u);
              }), window.history.pushState(t, "", d.toString());
            }, 100);
          },
          setAttributesGroup: (e) => n((t) => {
            t.attributesGroup = e;
          }),
          setAttributesTab: (e) => n((t) => {
            t.attributesTab = e;
          }),
          setIsResizing: (e) => n((t) => {
            t.resizing = e;
          }),
          setMouseOverPanel: (e) => n((t) => {
            t.isMouseOverPanel = e;
          }),
          setContextMenuVisible: (e) => n((t) => {
            t.contextMenuVisible = e;
          }),
          setDraggingBrickType: (e) => n((t) => {
            t.draggingBrickType = e ?? void 0;
          }),
          setGridConfig: (e) => n((t) => {
            t.gridConfig = e;
          }),
          toggleEditorEnabled: () => n((e) => {
            e.disabled = !e.disabled;
          }),
          toggleChat: () => n((e) => {
            e.chatVisible = !e.chatVisible, e.chatVisible && (e.panel = void 0, e.panelPosition = "right"), e.updateHistory();
          }),
          toggleDebugMode: () => n((e) => {
            e.debugMode = !e.debugMode;
          }),
          setPreviewMode: (e) => n((t) => {
            t.previewMode = e;
          }),
          setSettingsVisible: (e) => n((t) => {
            t.settingsVisible = e, t.updateHistory();
          }),
          toggleSettings: () => n((e) => {
            e.settingsVisible = !e.settingsVisible, e.updateHistory();
          }),
          setIsEditingText: (e) => n((t) => {
            t.isEditingTextForBrickId = e || void 0;
          }),
          setPanel: (e) => n((t) => {
            t.panel = e, t.updateHistory();
          }),
          togglePanel: (e) => n((t) => {
            t.panel = e && t.panel === e ? void 0 : e, t.updateHistory();
          }),
          hidePanel: (e) => n((t) => {
            (!e || t.panel === e) && (t.panel = void 0), t.updateHistory();
          }),
          toggleModal: (e) => n((t) => {
            t.modal = e && t.modal === e ? void 0 : e, t.updateHistory();
          }),
          zoomIn: () => n((e) => {
            e.zoom = Math.min(e.zoom + 0.1, 2);
          }),
          zoomOut: () => n((e) => {
            e.zoom = Math.max(e.zoom - 0.1, 0.5);
          }),
          resetZoom: () => n((e) => {
            e.zoom = 1;
          }),
          setSelectedGroup: (e) => n((t) => {
            t.selectedGroup = e;
          }),
          setSelectedBrickId: (e) => n((t) => {
            t.selectedBrickId = e, e && (t.selectedSectionId = void 0), t.updateHistory();
          }),
          setSelectedSectionId: (e) => n((t) => {
            t.selectedSectionId = e, e && (t.selectedBrickId = void 0, t.selectedGroup = void 0), t.updateHistory();
          }),
          deselectBrick: (e) => n((t) => {
            t.selectedBrickId && (!e || t.selectedBrickId === e) && (t.selectedBrickId = void 0), t.updateHistory();
          }),
          togglePanelPosition: () => n((e) => {
            e.panelPosition = e.panelPosition === "left" ? "right" : "left", e.updateHistory();
          }),
          showModal: (e) => n((t) => {
            t.modal = e, t.updateHistory();
          }),
          hideModal: () => n((e) => {
            e.modal = void 0, e.updateHistory();
          })
        })),
        // limit undo history to 100
        {
          limit: 100,
          equality: (n, c) => m(n, c)
        }
      )
    )
  );
}, v = S(null), s = () => {
  const i = x(v);
  return i || console.log("Problem with EditorStoreContext", i), a(i, "useEditorStoreContext must be used within a EditorStoreContext"), i;
}, D = () => {
  const i = s();
  return r(i);
}, A = () => {
  const i = s();
  return r(i, (o) => o.previewMode);
}, L = () => {
  const i = s();
  return r(i, (o) => !o.disabled);
}, R = () => {
  const i = s();
  return r(i, (o) => o.logoLink);
}, Z = () => {
  const i = s();
  return r(i, (o) => o.selectedGroup);
}, F = () => {
  const i = s();
  return r(i, (o) => o.selectedBrickId);
}, U = () => {
  const i = s();
  return r(i, (o) => o.attributesTab ?? "page");
}, W = () => {
  const i = s();
  return r(i, (o) => o.attributesGroup);
};
function _() {
  const i = s();
  return r(i, (o) => o.selectedSectionId);
}
function q() {
  const i = s(), o = I();
  return r(i, (n) => {
    const c = o.getState().page.sections.find((e) => e.id === n.selectedSectionId);
    return c || null;
  });
}
const j = () => {
  const i = s();
  return r(i, (o) => !!o.debugMode);
}, N = () => {
  const i = s();
  return r(i, (o) => ({
    panel: o.panel,
    panelPosition: o.panelPosition
  }));
}, Y = () => {
  const i = s();
  return r(i, (o) => o.modal);
}, J = () => {
  const i = s();
  return r(i, (o) => o.planIndex > 0);
};
function K(i) {
  const o = s();
  return r(o, (n) => n.planIndex >= i);
}
const Q = () => {
  const i = s();
  return r(i, (o) => o.themesLibrary);
}, X = () => {
  const i = s();
  return r(i, (o) => ({
    zoom: o.zoom,
    zoomIn: o.zoomIn,
    zoomOut: o.zoomOut,
    canZoomIn: o.zoom < 2,
    canZoomOut: o.zoom > 0.5,
    resetZoom: o.resetZoom
  }));
}, $ = () => {
  const i = s();
  return r(i, (o) => !!o.chatVisible);
}, ee = () => {
  const i = s();
  return r(i, (o) => o.resizing);
};
function oe() {
  const i = s();
  return r(i, (o) => o.isEditingTextForBrickId);
}
const te = () => {
  const i = s();
  return r(i, (o) => o.draggingBrickType);
}, ie = () => {
  const i = s();
  return r(i, (o) => o.contextMenuVisible);
}, ne = () => {
  const i = s();
  return r(i, (o) => ({
    setAttributesGroup: o.setAttributesGroup,
    setAttributesTab: o.setAttributesTab,
    setIsResizing: o.setIsResizing,
    setMouseOverPanel: o.setMouseOverPanel,
    toggleDebugMode: o.toggleDebugMode,
    setContextMenuVisible: o.setContextMenuVisible,
    setDraggingBrickType: o.setDraggingBrickType,
    setPreviewMode: o.setPreviewMode,
    setSettingsVisible: o.setSettingsVisible,
    setGridConfig: o.setGridConfig,
    toggleSettings: o.toggleSettings,
    setIsEditingText: o.setIsEditingText,
    setPanel: o.setPanel,
    togglePanel: o.togglePanel,
    toggleModal: o.toggleModal,
    hidePanel: o.hidePanel,
    setSelectedGroup: o.setSelectedGroup,
    setSelectedBrickId: o.setSelectedBrickId,
    setSelectedSectionId: o.setSelectedSectionId,
    deselectBrick: o.deselectBrick,
    togglePanelPosition: o.togglePanelPosition,
    showModal: o.showModal,
    hideModal: o.hideModal,
    toggleEditorEnabled: o.toggleEditorEnabled,
    onPublish: o.onPublish,
    onSavePage: o.onSavePage,
    onSaveSite: o.onSaveSite,
    onDraftChange: o.onDraftChange,
    toggleChat: o.toggleChat,
    onShowPopup: o.onShowPopup
  }));
};
function re() {
  const i = s();
  return r(
    i,
    (o) => o.gridConfig ?? {
      colWidth: 20,
      rowHeight: g
    }
  );
}
export {
  v as EditorStoreContext,
  O as createEditorStore,
  W as useAttributesGroup,
  U as useAttributesTab,
  $ as useChatVisible,
  ie as useContextMenuVisible,
  j as useDebugMode,
  te as useDraggingBrickType,
  oe as useEditingTextForBrickId,
  D as useEditor,
  L as useEditorEnabled,
  ne as useEditorHelpers,
  s as useEditorStoreContext,
  re as useGridConfig,
  K as useHasPlanOrHigher,
  J as useIsPremiumPlan,
  ee as useIsResizing,
  R as useLogoLink,
  Y as useModal,
  N as usePanel,
  A as usePreviewMode,
  F as useSelectedBrickId,
  Z as useSelectedGroup,
  q as useSelectedSection,
  _ as useSelectedSectionId,
  Q as useThemesLibrary,
  X as useZoom
};
//# sourceMappingURL=use-editor.js.map
