import { A as d, B as s, C as l, t as g, E as u, F as a, G as x, H as m, I as S } from "./use-page-data.ClF2QKbJ.js";
import { isEqual as h } from "lodash-es";
import { createContext as p, useContext as M } from "react";
/*! Upstart.gg - Copyright (C) 2024 Flippable - https://github.com/upstart-gg/upstart/blob/main/LICENSE */
var v = 24, b = 24;
d();
const C = (t) => {
  const e = {
    previewMode: "desktop",
    themesLibrary: [],
    pages: [],
    panelPosition: "left",
    logoLink: "/dashboard",
    zoom: 1,
    chatVisible: !0,
    contextMenuVisible: !1,
    planIndex: 0,
    imagesSearchResults: void 0,
    sitePrompt: "",
    onPublish: () => {
      console.warn("onPublish is not implemented");
    },
    onDraftChange: async () => {
      console.warn("onDraftChange is not implemented");
    },
    debugMode: !1
  };
  return u()(
    a(
      x(
        m(
          S((n, c) => ({
            ...e,
            ...t,
            setIsResizing: (o) => n((i) => {
              i.resizing = o;
            }),
            setMouseOverPanel: (o) => n((i) => {
              i.isMouseOverPanel = o;
            }),
            setContextMenuVisible: (o) => n((i) => {
              i.contextMenuVisible = o;
            }),
            setDraggingBrickType: (o) => n((i) => {
              i.draggingBrickType = o ?? void 0;
            }),
            setGridConfig: (o) => n((i) => {
              i.gridConfig = o;
            }),
            toggleEditorEnabled: () => n((o) => {
              o.disabled = !o.disabled;
            }),
            toggleChat: () => n((o) => {
              o.chatVisible = !o.chatVisible, o.chatVisible && (o.panel = void 0, o.panelPosition = "right");
            }),
            toggleDebugMode: () => n((o) => {
              o.debugMode = !o.debugMode;
            }),
            setImagesSearchResults: (o) => n((i) => {
              i.imagesSearchResults = o;
            }),
            toggleTextEditMode: () => n((o) => {
              o.textEditMode = !o.textEditMode || o.textEditMode === "default" ? "large" : "default";
            }),
            setTextEditMode: (o) => n((i) => {
              i.textEditMode = o;
            }),
            setPreviewMode: (o) => n((i) => {
              i.previewMode = o;
            }),
            setSettingsVisible: (o) => n((i) => {
              i.settingsVisible = o;
            }),
            toggleSettings: () => n((o) => {
              o.settingsVisible = !o.settingsVisible;
            }),
            setIsEditingText: (o) => n((i) => {
              i.isEditingTextForBrickId = o || void 0;
            }),
            setPanel: (o) => n((i) => {
              i.panel = o;
            }),
            togglePanel: (o) => n((i) => {
              i.panel = o && i.panel === o ? void 0 : o;
            }),
            hidePanel: (o) => n((i) => {
              (!o || i.panel === o) && (i.panel = void 0);
            }),
            zoomIn: () => n((o) => {
              o.zoom = Math.min(o.zoom + 0.1, 2);
            }),
            zoomOut: () => n((o) => {
              o.zoom = Math.max(o.zoom - 0.1, 0.5);
            }),
            resetZoom: () => n((o) => {
              o.zoom = 1;
            }),
            setSelectedGroup: (o) => n((i) => {
              i.selectedGroup = o;
            }),
            setSelectedBrickId: (o) => n((i) => {
              i.selectedBrickId = o, o && (i.selectedSectionId = void 0);
            }),
            setSelectedSectionId: (o) => n((i) => {
              i.selectedSectionId = o, o && (i.selectedBrickId = void 0, i.selectedGroup = void 0);
            }),
            deselectBrick: (o) => n((i) => {
              i.selectedBrickId && (!o || i.selectedBrickId === o) && (i.selectedBrickId = void 0);
            }),
            togglePanelPosition: () => n((o) => {
              o.panelPosition = o.panelPosition === "left" ? "right" : "left";
            }),
            showModal: (o) => n((i) => {
              i.modal = o;
            }),
            hideModal: () => n((o) => {
              o.modal = void 0;
            })
          })),
          // limit undo history to 100
          {
            limit: 100,
            equality: (n, c) => h(n, c)
          }
        ),
        {
          name: "editor-state",
          partialize: (n) => Object.fromEntries(
            Object.entries(n).filter(([c]) => ["chatVisible", "previewMode"].includes(c))
          )
        }
      )
    )
  );
}, P = p(null), r = () => {
  const t = M(P);
  return t || console.log("Problem with EditorStoreContext", t), g(t, "useEditorStoreContext must be used within a EditorStoreContext"), t;
}, k = () => {
  const t = r();
  return s(t);
}, z = () => {
  const t = r();
  return s(t, (e) => e.previewMode);
}, B = () => {
  const t = r();
  return s(t, (e) => !e.disabled);
}, T = () => {
  const t = r();
  return s(t, (e) => e.logoLink);
}, V = () => {
  const t = r();
  return s(t, (e) => e.selectedGroup);
}, w = () => {
  const t = r();
  return s(t, (e) => e.selectedBrickId);
};
function O() {
  const t = r();
  return s(t, (e) => e.selectedSectionId);
}
function D() {
  const t = r(), e = l();
  return s(t, (n) => {
    const c = e.getState().sections.find((o) => o.id === n.selectedSectionId);
    return c || null;
  });
}
const y = () => {
  const t = r();
  return s(t, (e) => !!e.debugMode);
}, G = () => {
  const t = r();
  return s(t, (e) => ({
    panel: e.panel,
    panelPosition: e.panelPosition
  }));
}, R = () => {
  const t = r();
  return s(t, (e) => e.planIndex > 0);
};
function L(t) {
  const e = r();
  return s(e, (n) => n.planIndex >= t);
}
const Z = () => {
  const t = r();
  return s(t, (e) => e.themesLibrary);
}, F = () => {
  const t = r();
  return s(t, (e) => e.imagesSearchResults);
}, H = () => {
  const t = r();
  return s(t, (e) => ({
    zoom: e.zoom,
    zoomIn: e.zoomIn,
    zoomOut: e.zoomOut,
    canZoomIn: e.zoom < 2,
    canZoomOut: e.zoom > 0.5,
    resetZoom: e.resetZoom
  }));
}, j = () => {
  const t = r();
  return s(t, (e) => !!e.chatVisible);
}, q = () => {
  const t = r();
  return s(t, (e) => e.textEditMode);
}, A = () => {
  const t = r();
  return s(t, (e) => e.resizing);
};
function W() {
  const t = r();
  return s(t, (e) => e.isEditingTextForBrickId);
}
const _ = () => {
  const t = r();
  return s(t, (e) => e.draggingBrickType);
}, U = () => {
  const t = r();
  return s(t, (e) => e.contextMenuVisible);
}, J = () => {
  const t = r();
  return s(t, (e) => e.isMouseOverPanel);
}, K = () => {
  const t = r();
  return s(t, (e) => ({
    setIsResizing: e.setIsResizing,
    setMouseOverPanel: e.setMouseOverPanel,
    toggleDebugMode: e.toggleDebugMode,
    setContextMenuVisible: e.setContextMenuVisible,
    setDraggingBrickType: e.setDraggingBrickType,
    setPreviewMode: e.setPreviewMode,
    setSettingsVisible: e.setSettingsVisible,
    setGridConfig: e.setGridConfig,
    toggleSettings: e.toggleSettings,
    toggleTextEditMode: e.toggleTextEditMode,
    setTextEditMode: e.setTextEditMode,
    setIsEditingText: e.setIsEditingText,
    setImagesSearchResults: e.setImagesSearchResults,
    setPanel: e.setPanel,
    togglePanel: e.togglePanel,
    hidePanel: e.hidePanel,
    setSelectedGroup: e.setSelectedGroup,
    setSelectedBrickId: e.setSelectedBrickId,
    setSelectedSectionId: e.setSelectedSectionId,
    deselectBrick: e.deselectBrick,
    togglePanelPosition: e.togglePanelPosition,
    showModal: e.showModal,
    hideModal: e.hideModal,
    toggleEditorEnabled: e.toggleEditorEnabled,
    onPublish: e.onPublish,
    onSavePage: e.onSavePage,
    onSaveSite: e.onSaveSite,
    onDraftChange: e.onDraftChange,
    toggleChat: e.toggleChat,
    onShowPopup: e.onShowPopup
  }));
};
function N() {
  const t = r();
  return s(
    t,
    (e) => e.gridConfig ?? {
      colWidth: 20,
      rowHeight: b
    }
  );
}
export {
  A,
  P as E,
  b as O,
  z as a,
  w as b,
  O as c,
  F as d,
  B as e,
  j as f,
  G as g,
  y as h,
  C as i,
  T as j,
  H as k,
  W as l,
  _ as m,
  J as n,
  v as o,
  N as p,
  k as q,
  R as r,
  D as s,
  U as t,
  K as u,
  r as v,
  V as w,
  L as x,
  Z as y,
  q as z
};
//# sourceMappingURL=use-editor.BioV43yU.js.map
