import { bb as a, bc as s, bd as g, a3 as b, be as p, bf as S, bg as x, bh as m } from "./use-page-data.BYLN5MSa.js";
import { isEqual as h, isNil as P } from "lodash-es";
import { createContext as I, useContext as M } from "react";
const B = 24, f = 24;
a();
const y = (i) => {
  const o = {
    previewMode: "desktop",
    themesLibrary: [],
    panelPosition: "left",
    logoLink: "/dashboard",
    zoom: 1,
    chatVisible: !0,
    contextMenuVisible: !1,
    planIndex: 0,
    attributesTab: "page",
    debugMode: !1
  };
  return p()(
    S(
      x(
        m((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]) => {
                !P(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) => h(n, c)
        }
      )
    )
  );
}, k = I(null), r = () => {
  const i = M(k);
  return i || console.log("Problem with EditorStoreContext", i), b(i, "useEditorStoreContext must be used within a EditorStoreContext"), i;
}, C = () => {
  const i = r();
  return s(i);
}, z = () => {
  const i = r();
  return s(i, (o) => o.previewMode);
}, w = () => {
  const i = r();
  return s(i, (o) => !o.disabled);
}, H = () => {
  const i = r();
  return s(i, (o) => o.logoLink);
}, V = () => {
  const i = r();
  return s(i, (o) => o.selectedGroup);
}, G = () => {
  const i = r();
  return s(i, (o) => o.selectedBrickId);
}, O = () => {
  const i = r();
  return s(i, (o) => o.attributesTab ?? "page");
}, L = () => {
  const i = r();
  return s(i, (o) => o.attributesGroup);
};
function A() {
  const i = r();
  return s(i, (o) => o.selectedSectionId);
}
function D() {
  const i = r(), o = g();
  return s(i, (n) => {
    const c = o.getState().page.sections?.find((e) => e.id === n.selectedSectionId);
    return c || null;
  });
}
const R = () => {
  const i = r();
  return s(i, (o) => !!o.debugMode);
}, Z = () => {
  const i = r();
  return s(i, (o) => ({
    panel: o.panel,
    panelPosition: o.panelPosition
  }));
}, U = () => {
  const i = r();
  return s(i, (o) => o.modal);
}, F = () => {
  const i = r();
  return s(i, (o) => o.planIndex > 0);
};
function _(i) {
  const o = r();
  return s(o, (n) => n.planIndex >= i);
}
const q = () => {
  const i = r();
  return s(i, (o) => o.themesLibrary);
}, W = () => {
  const i = r();
  return s(i, (o) => ({
    zoom: o.zoom,
    zoomIn: o.zoomIn,
    zoomOut: o.zoomOut,
    canZoomIn: o.zoom < 2,
    canZoomOut: o.zoom > 0.5,
    resetZoom: o.resetZoom
  }));
}, j = () => {
  const i = r();
  return s(i, (o) => o.chatSession);
}, Y = () => {
  const i = r();
  return s(i, (o) => !!o.chatVisible);
}, N = () => {
  const i = r();
  return s(i, (o) => o.resizing);
};
function J() {
  const i = r();
  return s(i, (o) => o.isEditingTextForBrickId);
}
const K = () => {
  const i = r();
  return s(i, (o) => o.draggingBrickType);
}, Q = () => {
  const i = r();
  return s(i, (o) => o.contextMenuVisible);
}, X = () => {
  const i = r();
  return s(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,
    // onSavePage: state.onSavePage,
    onSaveSite: o.onSaveSite,
    // onPageCreated: state.onPageCreated,
    toggleChat: o.toggleChat,
    onShowPopup: o.onShowPopup
  }));
};
function $() {
  const i = r();
  return s(
    i,
    (o) => o.gridConfig ?? {
      colWidth: 20,
      rowHeight: f
    }
  );
}
export {
  q as A,
  N as B,
  k as E,
  B as L,
  z as a,
  G as b,
  A as c,
  Y as d,
  Z as e,
  R as f,
  y as g,
  H as h,
  U as i,
  W as j,
  j as k,
  f as l,
  J as m,
  K as n,
  $ as o,
  O as p,
  L as q,
  D as r,
  C as s,
  F as t,
  X as u,
  Q as v,
  r as w,
  w as x,
  V as y,
  _ as z
};
