import { aA as e, aB as t, aC as n, av as r, aw as i, ax as a, ay as o, az as s, r as c } from "./use-page-data.Cb2SuuwJ.js";
import { isEqual as l, isNil as u } from "lodash-es";
import { createContext as d, useContext as f } from "react";
/*! Upstart.gg - Copyright (C) 2024 Flippable - https://github.com/upstart-gg/upstart/blob/main/LICENSE */
var p = 24, m = 24;
t();
const h = (t) => {
	let n = {
		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 e()(a(i(o(r((e, r) => ({
		...n,
		...t,
		updateHistory: () => {
			setTimeout(() => {
				let e = r(), t = {
					panel: e.panel,
					selectedBrickId: e.selectedBrickId,
					selectedSectionId: e.selectedBrickId ? void 0 : e.selectedSectionId,
					panelPosition: e.panelPosition,
					modal: e.modal,
					debug: void 0
				}, n = new URL(window.location.href);
				Object.entries(t).forEach(([e, t]) => {
					!u(t) && t.toString().trim() !== "" ? n.searchParams.set(e, t.toString()) : n.searchParams.delete(e);
				}), window.history.pushState(t, "", n.toString());
			}, 100);
		},
		setIsResizing: (t) => e((e) => {
			e.resizing = t;
		}),
		setMouseOverPanel: (t) => e((e) => {
			e.isMouseOverPanel = t;
		}),
		setContextMenuVisible: (t) => e((e) => {
			e.contextMenuVisible = t;
		}),
		setDraggingBrickType: (t) => e((e) => {
			e.draggingBrickType = t ?? void 0;
		}),
		setGridConfig: (t) => e((e) => {
			e.gridConfig = t;
		}),
		toggleEditorEnabled: () => e((e) => {
			e.disabled = !e.disabled;
		}),
		toggleChat: () => e((e) => {
			e.chatVisible = !e.chatVisible, e.chatVisible && (e.panel = void 0, e.panelPosition = "right"), e.updateHistory();
		}),
		toggleDebugMode: () => e((e) => {
			e.debugMode = !e.debugMode;
		}),
		setImagesSearchResults: (t) => e((e) => {
			e.imagesSearchResults = t;
		}),
		setPreviewMode: (t) => e((e) => {
			e.previewMode = t;
		}),
		setSettingsVisible: (t) => e((e) => {
			e.settingsVisible = t, e.updateHistory();
		}),
		toggleSettings: () => e((e) => {
			e.settingsVisible = !e.settingsVisible, e.updateHistory();
		}),
		setIsEditingText: (t) => e((e) => {
			e.isEditingTextForBrickId = t || void 0;
		}),
		setPanel: (t) => e((e) => {
			e.panel = t, e.updateHistory();
		}),
		togglePanel: (t) => e((e) => {
			e.panel = t && e.panel === t ? void 0 : t, e.updateHistory();
		}),
		hidePanel: (t) => e((e) => {
			(!t || e.panel === t) && (e.panel = void 0), e.updateHistory();
		}),
		toggleModal: (t) => e((e) => {
			e.modal = t && e.modal === t ? void 0 : t, e.updateHistory();
		}),
		zoomIn: () => e((e) => {
			e.zoom = Math.min(e.zoom + .1, 2);
		}),
		zoomOut: () => e((e) => {
			e.zoom = Math.max(e.zoom - .1, .5);
		}),
		resetZoom: () => e((e) => {
			e.zoom = 1;
		}),
		setSelectedGroup: (t) => e((e) => {
			e.selectedGroup = t;
		}),
		setSelectedBrickId: (t) => e((e) => {
			e.selectedBrickId = t, t && (e.selectedSectionId = void 0), e.updateHistory();
		}),
		setSelectedSectionId: (t) => e((e) => {
			e.selectedSectionId = t, t && (e.selectedBrickId = void 0, e.selectedGroup = void 0), e.updateHistory();
		}),
		deselectBrick: (t) => e((e) => {
			e.selectedBrickId && (!t || e.selectedBrickId === t) && (e.selectedBrickId = void 0), e.updateHistory();
		}),
		togglePanelPosition: () => e((e) => {
			e.panelPosition = e.panelPosition === "left" ? "right" : "left", e.updateHistory();
		}),
		showModal: (t) => e((e) => {
			e.modal = t, e.updateHistory();
		}),
		hideModal: () => e((e) => {
			e.modal = void 0, e.updateHistory();
		})
	})), {
		limit: 100,
		equality: (e, t) => l(e, t)
	}), {
		name: "editor-state",
		partialize: (e) => Object.fromEntries(Object.entries(e).filter(([e]) => ["chatVisible", "previewMode"].includes(e)))
	})));
}, g = d(null), _ = () => {
	let e = f(g);
	return e || console.log("Problem with EditorStoreContext", e), n(e, "useEditorStoreContext must be used within a EditorStoreContext"), e;
}, v = () => {
	let e = _();
	return s(e);
}, y = () => {
	let e = _();
	return s(e, (e) => e.previewMode);
}, b = () => {
	let e = _();
	return s(e, (e) => !e.disabled);
}, x = () => {
	let e = _();
	return s(e, (e) => e.logoLink);
}, S = () => {
	let e = _();
	return s(e, (e) => e.selectedGroup);
}, C = () => {
	let e = _();
	return s(e, (e) => e.selectedBrickId);
};
function w() {
	let e = _();
	return s(e, (e) => e.selectedSectionId);
}
function T() {
	let e = _(), t = c();
	return s(e, (e) => {
		let n = t.getState().sections.find((t) => t.id === e.selectedSectionId);
		return n || null;
	});
}
const E = () => {
	let e = _();
	return s(e, (e) => !!e.debugMode);
}, D = () => {
	let e = _();
	return s(e, (e) => ({
		panel: e.panel,
		panelPosition: e.panelPosition
	}));
}, O = () => {
	let e = _();
	return s(e, (e) => e.modal);
}, k = () => {
	let e = _();
	return s(e, (e) => e.planIndex > 0);
};
function A(e) {
	let t = _();
	return s(t, (t) => t.planIndex >= e);
}
const j = () => {
	let e = _();
	return s(e, (e) => e.themesLibrary);
}, M = () => {
	let e = _();
	return s(e, (e) => e.imagesSearchResults);
}, N = () => {
	let e = _();
	return s(e, (e) => ({
		zoom: e.zoom,
		zoomIn: e.zoomIn,
		zoomOut: e.zoomOut,
		canZoomIn: e.zoom < 2,
		canZoomOut: e.zoom > .5,
		resetZoom: e.resetZoom
	}));
}, P = () => {
	let e = _();
	return s(e, (e) => !!e.chatVisible);
}, F = () => {
	let e = _();
	return s(e, (e) => e.resizing);
};
function I() {
	let e = _();
	return s(e, (e) => e.isEditingTextForBrickId);
}
const L = () => {
	let e = _();
	return s(e, (e) => e.draggingBrickType);
}, R = () => {
	let e = _();
	return s(e, (e) => e.contextMenuVisible);
}, z = () => {
	let e = _();
	return s(e, (e) => e.isMouseOverPanel);
}, B = () => {
	let e = _();
	return s(e, (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,
		setIsEditingText: e.setIsEditingText,
		setImagesSearchResults: e.setImagesSearchResults,
		setPanel: e.setPanel,
		togglePanel: e.togglePanel,
		toggleModal: e.toggleModal,
		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 V() {
	let e = _();
	return s(e, (e) => e.gridConfig ?? {
		colWidth: 20,
		rowHeight: m
	});
}
export { j as A, N as B, m as C, p as D, g as b, h as c, P as d, R as e, E as f, L as g, I as h, v as i, b as j, B as k, _ as l, V as m, A as n, M as o, z as p, k as q, F as r, x as s, O as t, D as u, y as v, C as w, S as x, T as y, w as z };

//# sourceMappingURL=use-editor.C-_8sOOa.js.map