import { h as e } from "./chunks/chunk.BlbRoQQ3.js";
import { d as t, f as n, j as r, k as i, o as a, t as o, u as s, v as c, w as l, z as u } from "./chunks/use-editor.C-_8sOOa.js";
import { A as d, B as f, F as p, H as m, K as h, L as g, M as _, N as ee, ad as v, e as y, g as b, h as x, i as te, j as ne, q as re, s as ie, u as ae } from "./chunks/use-page-data.Cb2SuuwJ.js";
import "./chunks/chunk-LSPN22SI.D75E3zS-.js";
import { b as S, c as C, d as oe } from "./chunks/twind.BiM9xcCd.js";
import { b as se, c as ce } from "./chunks/system.DbMQd1I1.js";
import { b as w } from "./chunks/jsx-runtime.DF4K5VCp.js";
import "./chunks/theme.HtT_2QlC.js";
import "./chunks/base-menu.props.BWy5Ub-q.js";
import { B as T, C as E, D, E as O, F as le, G as ue, H as de, I as fe, J as pe, b as k, d as me, h as he, i as ge, j as _e, p as ve, q as ye, r as A, w as be, x as j, y as xe, z as M } from "./chunks/field-factory.Y38Qqp5L.js";
import "./chunks/text.CvSXsyI-.js";
import "./chunks/height.props.DCx-mV3G.js";
import "./chunks/base-button.ClgpqKOM.js";
import { f as N } from "./chunks/colors.B0ZQIUWB.js";
import { h as P } from "./chunks/use-editable-text.LuBbyeSP.js";
import "./chunks/dropdown-menu.DOURzgMR.js";
import { b as F } from "./chunks/tooltip.D4rQGwev.js";
import { c as Se } from "./chunks/dist.ccQGo6gv.js";
import "./chunks/chroma-js.Dcir27CH.js";
import "./chunks/color-system.Dp99zR0T.js";
import { b as Ce } from "./chunks/get-theme-css.Cu_T1VYf.js";
import { b as we } from "./chunks/react.BZZIbN3T.js";
import "./chunks/iconBase.C7m0emOO.js";
import { d as Te, k as Ee, l as De, n as Oe, p as ke } from "./chunks/lu.1OtQ5qAt.js";
import { m as I } from "./chunks/schema-resolver.p7B_pu36.js";
import "./chunks/io.Bu1sIxQU.js";
import "./chunks/md.Dru5DXQh.js";
import { b as Ae } from "./chunks/rx.CwXTGsxR.js";
import { f as je } from "./chunks/tb.BLWNpC3s.js";
import "./chunks/react-is.DZ6rX8e9.js";
import "./chunks/UploaderContext.BQZH1D99.js";
import "./chunks/iconify.BzZOJCu5.js";
import { d as Me } from "./chunks/fi.C2Y09MnC.js";
import "./chunks/vsc.B-e9du85.js";
import "./chunks/hi2.LBKfascG.js";
import "./chunks/menubar-styles.CdETFVyL.js";
import "./chunks/use-datarecord.Hg48JvBA.js";
import { isEqual as Ne } from "lodash-es";
import { Fragment as Pe, Suspense as L, createContext as Fe, lazy as R, useCallback as z, useContext as Ie, useEffect as B, useLayoutEffect as Le, useRef as V, useState as H } from "react";
import { Type as U } from "@sinclair/typebox";
const Re = 1e3;
function ze() {
	let e = b(), t = ie(), { onSavePage: n, onSaveSite: r } = i(), a = Se(async (r) => {
		await n?.({
			pageId: t.id,
			pageVersionId: "latest",
			siteId: t.siteId,
			data: r
		}), e.setDirty(!1);
	}, Re), o = Se(async (n) => {
		await r?.({
			siteId: t.siteId,
			data: n
		}), e.setDirty(!1);
	}, Re);
	f((e) => {
		console.debug("Sections have changed, updating page version", e), a({ sections: e });
	}), re((e) => {
		console.debug("Page attributes have changed:", e), a({ attributes: e });
	}), p((e) => {
		console.debug("Site attributes have changed:", e), o({ attributes: e });
	}), ae((e) => {
		console.debug("pagePath has changed, updating page version"), a({ path: e });
	}), g((e) => {
		console.debug("theme has changed, updating page version"), o({ theme: e });
	});
}
var W = /* @__PURE__ */ e(w());
function G() {
	return G = Object.assign ? Object.assign.bind() : function(e) {
		for (var t = 1; t < arguments.length; t++) {
			var n = arguments[t];
			for (var r in n) ({}).hasOwnProperty.call(n, r) && (e[r] = n[r]);
		}
		return e;
	}, G.apply(null, arguments);
}
var Be = [
	"shift",
	"alt",
	"meta",
	"mod",
	"ctrl"
], Ve = {
	esc: "escape",
	return: "enter",
	".": "period",
	",": "comma",
	"-": "slash",
	" ": "space",
	"`": "backquote",
	"#": "backslash",
	"+": "bracketright",
	ShiftLeft: "shift",
	ShiftRight: "shift",
	AltLeft: "alt",
	AltRight: "alt",
	MetaLeft: "meta",
	MetaRight: "meta",
	OSLeft: "meta",
	OSRight: "meta",
	ControlLeft: "ctrl",
	ControlRight: "ctrl"
};
function K(e) {
	return (e && Ve[e] || e || "").trim().toLowerCase().replace(/key|digit|numpad|arrow/, "");
}
function He(e) {
	return Be.includes(e);
}
function q(e, t) {
	return t === void 0 && (t = ","), e.split(t);
}
function J(e, t, n) {
	t === void 0 && (t = "+");
	var r = e.toLocaleLowerCase().split(t).map(function(e) {
		return K(e);
	}), i = {
		alt: r.includes("alt"),
		ctrl: r.includes("ctrl") || r.includes("control"),
		shift: r.includes("shift"),
		meta: r.includes("meta"),
		mod: r.includes("mod")
	}, a = r.filter(function(e) {
		return !Be.includes(e);
	});
	return G({}, i, {
		keys: a,
		description: n,
		hotkey: e
	});
}
(function() {
	typeof document < "u" && (document.addEventListener("keydown", function(e) {
		e.key !== void 0 && We([K(e.key), K(e.code)]);
	}), document.addEventListener("keyup", function(e) {
		e.key !== void 0 && Ge([K(e.key), K(e.code)]);
	})), typeof window < "u" && window.addEventListener("blur", function() {
		Y.clear();
	});
})();
var Y = /* @__PURE__ */ new Set();
function X(e) {
	return Array.isArray(e);
}
function Ue(e, t) {
	t === void 0 && (t = ",");
	var n = X(e) ? e : e.split(t);
	return n.every(function(e) {
		return Y.has(e.trim().toLowerCase());
	});
}
function We(e) {
	var t = Array.isArray(e) ? e : [e];
	Y.has("meta") && Y.forEach(function(e) {
		return !He(e) && Y.delete(e.toLowerCase());
	}), t.forEach(function(e) {
		return Y.add(e.toLowerCase());
	});
}
function Ge(e) {
	var t = Array.isArray(e) ? e : [e];
	e === "meta" ? Y.clear() : t.forEach(function(e) {
		return Y.delete(e.toLowerCase());
	});
}
function Ke(e, t, n) {
	(typeof n == "function" && n(e, t) || n === !0) && e.preventDefault();
}
function qe(e, t, n) {
	return typeof n == "function" ? n(e, t) : n === !0 || n === void 0;
}
function Je(e) {
	return Ye(e, [
		"input",
		"textarea",
		"select"
	]);
}
function Ye(e, t) {
	t === void 0 && (t = !1);
	var n = e.target, r = e.composed, i = null;
	return i = Xe(n) && r ? e.composedPath()[0] && e.composedPath()[0].tagName : n && n.tagName, X(t) ? !!(i && t && t.some(function(e) {
		var t;
		return e.toLowerCase() === (t = i)?.toLowerCase();
	})) : !!(i && t && t);
}
function Xe(e) {
	return !!e.tagName && !e.tagName.startsWith("-") && e.tagName.includes("-");
}
function Ze(e, t) {
	return e.length === 0 && t ? (console.warn("A hotkey has the \"scopes\" option set, however no active scopes were found. If you want to use the global scopes feature, you need to wrap your app in a <HotkeysProvider>"), !0) : t ? e.some(function(e) {
		return t.includes(e);
	}) || e.includes("*") : !0;
}
var Qe = function(e, t, n) {
	n === void 0 && (n = !1);
	var r = t.alt, i = t.meta, a = t.mod, o = t.shift, s = t.ctrl, c = t.keys, l = e.key, u = e.code, d = e.ctrlKey, f = e.metaKey, p = e.shiftKey, m = e.altKey, h = K(u), g = l.toLowerCase();
	if (!(c != null && c.includes(h)) && !(c != null && c.includes(g)) && ![
		"ctrl",
		"control",
		"unknown",
		"meta",
		"alt",
		"shift",
		"os"
	].includes(h)) return !1;
	if (!n) {
		if (r === !m && g !== "alt" || o === !p && g !== "shift") return !1;
		if (a) {
			if (!f && !d) return !1;
		} else if (i === !f && g !== "meta" && g !== "os" || s === !d && g !== "ctrl" && g !== "control") return !1;
	}
	return c && c.length === 1 && (c.includes(g) || c.includes(h)) ? !0 : c ? Ue(c) : !c;
}, $e = /* @__PURE__ */ Fe(void 0), et = function() {
	return Ie($e);
};
function tt(e, t) {
	return e && t && typeof e == "object" && typeof t == "object" ? Object.keys(e).length === Object.keys(t).length && Object.keys(e).reduce(function(n, r) {
		return n && tt(e[r], t[r]);
	}, !0) : e === t;
}
var nt = /* @__PURE__ */ Fe({
	hotkeys: [],
	enabledScopes: [],
	toggleScope: function() {},
	enableScope: function() {},
	disableScope: function() {}
}), rt = function() {
	return Ie(nt);
};
function it(e) {
	var t = V(void 0);
	return tt(t.current, e) || (t.current = e), t.current;
}
var at = function(e) {
	e.stopPropagation(), e.preventDefault(), e.stopImmediatePropagation();
}, ot = typeof window < "u" ? Le : B;
function Z(e, t, n, r) {
	var i = H(null), a = i[0], o = i[1], s = V(!1), c = n instanceof Array ? r instanceof Array ? void 0 : r : n, l = X(e) ? e.join(c?.splitKey) : e, u = n instanceof Array ? n : r instanceof Array ? r : void 0, d = z(t, u ?? []), f = V(d);
	u ? f.current = d : f.current = t;
	var p = it(c), m = rt(), h = m.enabledScopes, g = et();
	return ot(function() {
		if (!(p?.enabled === !1 || !Ze(h, p?.scopes))) {
			var e = function(e, t) {
				var n;
				if (t === void 0 && (t = !1), !(Je(e) && !Ye(e, p?.enableOnFormTags))) {
					if (a !== null) {
						var r = a.getRootNode();
						if ((r instanceof Document || r instanceof ShadowRoot) && r.activeElement !== a && !a.contains(r.activeElement)) {
							at(e);
							return;
						}
					}
					(n = e.target) != null && n.isContentEditable && !(p != null && p.enableOnContentEditable) || q(l, p?.splitKey).forEach(function(n) {
						var r, i = J(n, p?.combinationKey);
						if (Qe(e, i, p?.ignoreModifiers) || (r = i.keys) != null && r.includes("*")) {
							if (p != null && p.ignoreEventWhen != null && p.ignoreEventWhen(e) || t && s.current) return;
							if (Ke(e, i, p?.preventDefault), !qe(e, i, p?.enabled)) {
								at(e);
								return;
							}
							f.current(e, i), t || (s.current = !0);
						}
					});
				}
			}, t = function(t) {
				t.key !== void 0 && (We(K(t.code)), (p?.keydown === void 0 && p?.keyup !== !0 || p != null && p.keydown) && e(t));
			}, n = function(t) {
				t.key !== void 0 && (Ge(K(t.code)), s.current = !1, p != null && p.keyup && e(t, !0));
			}, r = a || c?.document || document;
			return r.addEventListener("keyup", n), r.addEventListener("keydown", t), g && q(l, p?.splitKey).forEach(function(e) {
				return g.addHotkey(J(e, p?.combinationKey, p?.description));
			}), function() {
				r.removeEventListener("keyup", n), r.removeEventListener("keydown", t), g && q(l, p?.splitKey).forEach(function(e) {
					return g.removeHotkey(J(e, p?.combinationKey, p?.description));
				});
			};
		}
	}, [
		a,
		l,
		p,
		h
	]), o;
}
function st() {
	let e = i(), t = x(), n = b(), r = c(), a = l(), o = u(), s = y(a), { undo: d, redo: f } = te();
	Z("esc", () => {
		e.deselectBrick(), e.setSelectedSectionId(), e.hidePanel();
	}), Z("mod+c", () => {
		let e = window.getSelection();
		e?.rangeCount || console.debug("mod+c pressed");
	}), Z(["backspace", "del"], (n) => {
		a && (n.preventDefault(), t.deleteBrick(a), e.deselectBrick(a), e.hidePanel("inspector"));
	}), Z("s", (t) => {
		t.preventDefault(), e.togglePanel("settings");
	}), Z("l", (t) => {
		t.preventDefault(), e.togglePanel("library");
	}), Z("t", (t) => {
		t.preventDefault(), e.togglePanel("theme");
	}), Z("p", (t) => {
		t.preventDefault(), e.togglePanel();
	}), Z(["mod+z", "ctrl+z"], (e) => {
		e.preventDefault(), d();
	}), Z(["mod+shift+z", "ctrl+shift+z"], (e) => {
		e.preventDefault(), f();
	}), Z(["up", "left"], (e) => {
		if (a) {
			e.preventDefault();
			let n = t.getParentBrick(a);
			if (n) {
				let r = n.props.direction === "flex-row" ? "ArrowLeft" : "ArrowUp";
				r === e.key && t.moveBrick(a, "previous");
			} else e.key === "ArrowLeft" && t.moveBrick(a, "previous");
		} else if (o && e.key === "ArrowUp") {
			e.preventDefault(), t.moveSectionUp(o);
			let n = document.getElementById(o);
			n && n.scrollIntoView({
				behavior: "smooth",
				block: "center"
			});
		}
	}, { enableOnContentEditable: !1 }), Z(["down", "right"], (e) => {
		if (a) {
			e.preventDefault();
			let n = t.getParentBrick(a);
			if (n) {
				let r = n.props.direction === "flex-row" ? "ArrowRight" : "ArrowDown";
				r === e.key && t.moveBrick(a, "next");
			} else e.key === "ArrowRight" && t.moveBrick(a, "next");
		} else if (o && e.key === "ArrowDown") {
			e.preventDefault(), t.moveSectionDown(o);
			let n = document.getElementById(o);
			n && n.scrollIntoView({
				behavior: "smooth",
				block: "center"
			});
		}
	}, { enableOnContentEditable: !1 }), Z("mod+d", (e) => {
		e.preventDefault(), a && (t.duplicateBrick(a), ce("Brick duplicated", { id: "duplicate-brick" }));
	}), Z("mod+j", (t) => {
		t.preventDefault(), e.toggleEditorEnabled();
	}), Z("mod+g", (e) => {
		e.preventDefault(), console.log("Debugging draft:");
		let { sections: t, themes: r, siteAttributes: i, sitemap: a, pageAttributes: o, brickMap: s } = n;
		console.log({
			sections: t,
			themes: r,
			siteAttributes: i,
			sitemap: a,
			pageAttributes: o,
			brickMap: s
		});
	}), Z("space", (e) => {
		let n = e.target;
		n.classList.contains("tiptap") || (e.preventDefault(), e.stopPropagation(), s && t.updateBrickProps(s.id, { grow: !s.props.grow }, r === "mobile"));
	}, { enableOnContentEditable: !0 });
}
function ct({ themes: e }) {
	let [t, n] = H(0), [r, i] = H(0), o = V(null), s = V(null), c = a(), l = e[t];
	return B(() => {
		let t = setInterval(() => {
			n((t) => (t + 1) % e.length), c?.length && i((e) => (e + 1) % c.length);
		}, 1e4);
		return () => clearInterval(t);
	}, [e, c]), B(() => {
		s.current?.style.setProperty("background-color", l.colors.base200), o.current?.style.setProperty("background-image", `conic-gradient(from 0deg, ${l.colors.primary}, ${l.colors.secondary}, ${l.colors.accent}, ${l.colors.primary})`);
	}, [l]), /* @__PURE__ */ (0, W.jsxs)("div", {
		ref: s,
		className: C("w-full flex justify-center items-center h-full relative overflow-hidden animate-background bg-size[400%] opacity-50", S({
			backgroundImage: c ? `url(${c[r]?.url})` : "none",
			backgroundSize: "cover"
		})),
		children: [/* @__PURE__ */ (0, W.jsx)("div", {
			ref: o,
			className: C("absolute w-[100vh] h-[100vh] inset-0 animate-spin-blob z-20")
		}), /* @__PURE__ */ (0, W.jsx)("div", {
			className: C("rounded-full absolute backdrop-blur-3xl inset-0 scale-150 bg-white/40 z-50 flex items-center justify-center", S({
				textShadow: "0 0 3px rgba(0, 0, 0, 0.3)",
				color: "#FFFFFF",
				fontSize: "1.2rem",
				fontWeight: "bold",
				transition: "color 0.3s ease, background-color 0.3s ease"
			})),
			children: l.name
		})]
	});
}
function lt() {
	return ne(), h(), /* @__PURE__ */ (0, W.jsx)("div", {
		className: C("absolute bg-gray-200 top-0 bottom-0 left-0 right-0 flex items-center justify-center"),
		children: /* @__PURE__ */ (0, W.jsxs)("h2", {
			className: C("text-gray-400 leading-relaxed text-xl font-semibold flex-1 text-center !font-sans"),
			children: [
				"Welcome!",
				/* @__PURE__ */ (0, W.jsx)("br", {}),
				"To get started, please answer a few questions from our beloved Bot, Upsie.",
				/* @__PURE__ */ (0, W.jsx)("br", {}),
				"Your site will then appear here... 🤩"
			]
		})
	});
}
function ut() {
	return globalThis.location?.hostname === "localhost";
}
var dt = Object.defineProperty, ft = Object.defineProperties, pt = Object.getOwnPropertyDescriptors, mt = Object.getOwnPropertySymbols, ht = Object.prototype.hasOwnProperty, gt = Object.prototype.propertyIsEnumerable, _t = (e, t, n) => t in e ? dt(e, t, {
	enumerable: !0,
	configurable: !0,
	writable: !0,
	value: n
}) : e[t] = n, vt = (e, t) => {
	for (var n in t ||= {}) ht.call(t, n) && _t(e, n, t[n]);
	if (mt) for (var n of mt(t)) gt.call(t, n) && _t(e, n, t[n]);
	return e;
}, yt = (e, t) => ft(e, pt(t));
function bt(e, t, n) {
	if (t === n) return e;
	let r = e.slice();
	return r.splice(n, 0, r.splice(t, 1)[0]), r;
}
function xt(e, t, n) {
	var r, i;
	let { source: a, target: o, canceled: s } = t.operation;
	if (!a || !o || s) return "preventDefault" in t && t.preventDefault(), e;
	let c = (e, t) => e === t || typeof e == "object" && "id" in e && e.id === t;
	if (Array.isArray(e)) {
		let t = e.findIndex((e) => c(e, a.id)), r = e.findIndex((e) => c(e, o.id));
		if (t === -1 || r === -1) return e;
		if (!s && "index" in a && typeof a.index == "number") {
			let r = a.index;
			if (r !== t) return n(e, t, r);
		}
		return n(e, t, r);
	}
	let l = Object.entries(e), u = -1, d, f = -1, p;
	for (let [e, t] of l) if (u === -1 && (u = t.findIndex((e) => c(e, a.id)), u !== -1 && (d = e)), f === -1 && (f = t.findIndex((e) => c(e, o.id)), f !== -1 && (p = e)), u !== -1 && f !== -1) break;
	if (!a.manager) return e;
	let { dragOperation: m } = a.manager, h = (i = (r = m.shape)?.current.center) ?? m.position.current;
	if (p == null && o.id in e) {
		let t = o.shape && h.y > o.shape.center.y ? e[o.id].length : 0;
		p = o.id, f = t;
	}
	if (d == null || p == null || d === p && u === f) return "preventDefault" in t && t.preventDefault(), e;
	if (d === p) return yt(vt({}, e), { [d]: n(e[d], u, f) });
	let g = o.shape && Math.round(h.y) > Math.round(o.shape.center.y), _ = g ? 1 : 0, ee = e[d][u];
	return yt(vt({}, e), {
		[d]: [...e[d].slice(0, u), ...e[d].slice(u + 1)],
		[p]: [
			...e[p].slice(0, f + _),
			ee,
			...e[p].slice(f + _)
		]
	});
}
function St(e, t) {
	return xt(e, t, bt);
}
U.Array(U.Object({
	title: U.Optional(U.String({
		title: "Title",
		description: "The title of the RSS feed item"
	})),
	link: U.Optional(U.String({
		title: "Link",
		description: "The link to the RSS feed item"
	})),
	creator: U.Optional(U.String({
		title: "Creator",
		description: "The creator of the RSS feed item"
	})),
	content: U.Optional(U.String({
		title: "Content",
		description: "The content of the RSS feed item"
	})),
	pubDate: U.Optional(U.String({
		title: "Pub Date",
		description: "The publication date of the RSS feed item"
	}))
}), {
	title: "RSS Feed",
	description: "RSS feed items"
}), U.Array(U.Object({
	etag: U.String(),
	id: U.Object({
		videoId: U.String(),
		channelId: U.String(),
		playlistId: U.String()
	}),
	snippet: U.Object({
		publishedAt: U.String(),
		channelId: U.String(),
		title: U.String(),
		description: U.String(),
		thumbnails: U.Object({
			default: U.Object({
				url: U.String(),
				width: U.Number(),
				height: U.Number()
			}),
			standard: U.Object({
				url: U.String(),
				width: U.Number(),
				height: U.Number()
			})
		}),
		channelTitle: U.String(),
		liveBroadcastContent: U.String()
	})
}), {
	title: "Youtube list schema",
	description: "Schema for a list of Youtube videos"
}), U.Array(U.Object({
	title: U.String({
		title: "Title",
		description: "Blog post title"
	}),
	excerpt: U.String({
		title: "Excerpt",
		description: "Short summary of the blog post",
		format: "markdown"
	}),
	image: U.Optional(U.String({
		title: "Image URL",
		format: "uri",
		description: "Blog post image"
	})),
	content: U.String({
		title: "Content",
		description: "Blog post content",
		format: "markdown"
	}),
	author: U.Object({ name: U.String({
		title: "Author Name",
		description: "Author's name"
	}) }),
	publishedAt: U.String({
		title: "Published Date",
		format: "date",
		description: "Publication date in ISO format"
	}),
	slug: U.String({
		title: "Slug",
		pattern: "^[a-z0-9]+(?:-[a-z0-9]+)*$",
		description: "URL-friendly version of the title"
	}),
	status: U.Union([
		U.Literal("draft"),
		U.Literal("published"),
		U.Literal("archived")
	], {
		title: "Status",
		description: "Publication status of the blog post"
	}),
	categories: U.Optional(U.Array(U.String({
		title: "Categories",
		description: "Blog post categories"
	}))),
	tags: U.Optional(U.Array(U.String({
		title: "Tags",
		description: "Blog post tags"
	})))
}), {
	title: "Blog Posts",
	description: "List of blog posts"
}), U.Array(U.Object({
	title: U.String({
		title: "Release Title",
		description: "Title of the release"
	}),
	version: U.Optional(U.String({
		title: "Version",
		description: "Version number"
	})),
	date: U.String({
		title: "Release Date",
		format: "date",
		description: "Release date in ISO format"
	}),
	changes: U.Array(U.Object({
		type: U.Union([
			U.Literal("added"),
			U.Literal("changed"),
			U.Literal("fixed"),
			U.Literal("improved"),
			U.Literal("deprecated"),
			U.Literal("removed")
		], { title: "Change Type" }),
		description: U.String({
			title: "Description",
			format: "markdown"
		})
	}))
}), {
	title: "Changelog",
	description: "Changelog items"
}), U.Array(U.Object({
	question: U.String({
		title: "Question",
		format: "markdown"
	}),
	answer: U.String({
		title: "Answer",
		format: "markdown"
	}),
	category: U.Optional(U.String({ title: "Category" })),
	tags: U.Optional(U.Array(U.String(), { title: "Tags" })),
	order: U.Optional(U.Number({ title: "Order in the list" }))
}), {
	title: "FAQ",
	description: "Schema representing a collection of frequently asked questions (FAQ)"
}), U.Array(U.Object({
	url: U.String({
		format: "uri",
		title: "URL"
	}),
	title: U.String({ title: "Title" }),
	description: U.Optional(U.String({
		title: "Description",
		format: "markdown"
	})),
	icon: U.Optional(U.String({
		title: "Icon",
		format: "uri"
	}))
}), { description: "Schema representing a collection of links" }), U.Array(U.Object({
	title: U.String({ title: "Title" }),
	description: U.String({
		title: "Description",
		format: "markdown"
	}),
	time: U.String({ title: "Time to prepare the recipe" }),
	ingredients: U.Array(U.Object({
		name: U.String({ title: "Name of the ingredient" }),
		quantity: U.String({ title: "Quantity of the ingredient" })
	})),
	steps: U.Array(U.Object({
		title: U.String({ title: "Step title" }),
		description: U.String({ title: "Step description" })
	}))
}), {
	title: "Recipes",
	description: "Collection of recipes"
});
function Ct(e) {
	if (!("indexes" in e)) return console.error("no datasource or indexes found", e), [];
	let t = e.schema?.items?.properties || {};
	return Array.from(new Set(e.indexes?.map((e) => e.fields[0]) ?? [])).map((e) => ({
		value: e,
		title: t[e]?.title || e
	}));
}
function wt() {
	let e = o(), { hideModal: t } = i();
	return /* @__PURE__ */ (0, W.jsx)(pe, {
		open: !!e,
		onOpenChange: (e) => {
			e || t();
		},
		children: e === "queries" && /* @__PURE__ */ (0, W.jsx)(Tt, {})
	});
}
function Tt() {
	let [e, t] = H(!1), [n, r] = H(null), a = i(), o = m(), s = ye(), { hideModal: c } = i();
	return /* @__PURE__ */ (0, W.jsxs)(fe, {
		"aria-describedby": "Queries managament",
		maxWidth: "760px",
		minHeight: "80dvh",
		className: "overflow-y-clip flex flex-col gap-y-2",
		children: [
			/* @__PURE__ */ (0, W.jsxs)(ue, {
				className: "flex items-center gap-3 pl-0 -ml-3",
				children: [
					/* @__PURE__ */ (0, W.jsx)(Oe, { className: "h-6 w-6 text-upstart-600" }),
					"Manage site queries",
					/* @__PURE__ */ (0, W.jsxs)(N, {
						size: "2",
						disabled: !s.length || e,
						variant: "outline",
						radius: "medium",
						className: C("!ml-auto", e && "!opacity-0"),
						onClick: () => {
							r(null), t(!0);
						},
						children: [/* @__PURE__ */ (0, W.jsx)(Te, { className: "w-4 h-4" }), "Create Query"]
					})
				]
			}),
			/* @__PURE__ */ (0, W.jsxs)(de, { children: [
				"Queries are used to fetch data from your databases. Once defined you can use them in your",
				" ",
				/* @__PURE__ */ (0, W.jsx)("button", {
					type: "button",
					className: C("text-upstart-600 hover:underline underline-offset-4"),
					onClick: () => {
						c(), a.setPanel("settings");
					},
					children: "page settings"
				}),
				" ",
				"and reference them to loop over or use their fields in bricks to display dynamic data."
			] }),
			e && /* @__PURE__ */ (0, W.jsx)(Et, {
				query: n,
				onClose: () => t(!1)
			}),
			!e && o.length === 0 && /* @__PURE__ */ (0, W.jsx)("div", {
				className: "flex flex-col gap-2 justify-center items-center flex-1 text-center",
				children: /* @__PURE__ */ (0, W.jsxs)("span", {
					className: "text-base text-gray-500",
					children: [
						"You currently have no queries defined.",
						/* @__PURE__ */ (0, W.jsx)("br", {}),
						"Create a new query to get started."
					]
				})
			}),
			o.length > 0 && /* @__PURE__ */ (0, W.jsx)("div", {
				className: "flex flex-col border border-gray-200 rounded-lg overflow-hidden -mx-1 mt-3 shadow-sm",
				children: o.map((e) => /* @__PURE__ */ (0, W.jsxs)("div", {
					className: "flex items-center justify-between p-4 [&:not(:last-child)]:border-b border-gray-200 ",
					children: [/* @__PURE__ */ (0, W.jsxs)("div", {
						className: "flex flex-col gap-2",
						children: [/* @__PURE__ */ (0, W.jsx)("div", {
							className: "font-medium",
							children: e.label
						}), /* @__PURE__ */ (0, W.jsxs)("div", {
							className: "flex gap-6 items-center justify-start text-sm  text-gray-500",
							children: [
								/* @__PURE__ */ (0, W.jsx)(F, {
									content: "Database",
									children: /* @__PURE__ */ (0, W.jsxs)("span", {
										className: "inline-flex gap-1 items-center cursor-help",
										children: [/* @__PURE__ */ (0, W.jsx)(De, { className: "text-upstart-500" }), e.datasourceId]
									})
								}),
								/* @__PURE__ */ (0, W.jsx)(F, {
									content: "Number of items",
									children: /* @__PURE__ */ (0, W.jsxs)("span", {
										className: "inline-flex gap-1 items-center cursor-help",
										children: [/* @__PURE__ */ (0, W.jsx)(ke, { className: "text-upstart-500" }), e.limit]
									})
								}),
								(e.parameters?.length ?? 0) > 0 && /* @__PURE__ */ (0, W.jsx)(F, {
									content: "Parameters",
									children: /* @__PURE__ */ (0, W.jsxs)("span", {
										className: "inline-flex gap-1 items-center cursor-help",
										children: [/* @__PURE__ */ (0, W.jsx)(Ee, { className: "text-upstart-500" }), e.parameters.join(", ")]
									})
								})
							]
						})]
					}), /* @__PURE__ */ (0, W.jsx)(P, {
						size: "2",
						variant: "soft",
						color: "violet",
						onClick: () => {
							r(e), t(!0);
						},
						children: /* @__PURE__ */ (0, W.jsx)(Me, { className: "w-4 h-4" })
					})]
				}, e.id))
			})
		]
	});
}
function Q() {
	return {
		id: he(7),
		filters: {
			op: "and",
			fields: []
		},
		sortField: "$publicationDate",
		sortDirection: "desc",
		limit: 10
	};
}
function Et({ query: e, onClose: t }) {
	let [n, r] = H(e ?? Q()), i = () => {
		r(Q());
	}, { upsertQuery: a } = x(), o = ye(), s = ve(n?.datasourceId), c = s ? Ct(s) : [], l = c.filter((e) => ["$id", "$slug"].includes(e.value) === !1), u = n?.filters?.fields?.filter((e) => "field" in e) ?? [], d = (e, t) => {
		r((n) => ({
			...n,
			sortDirection: e === "sortField" && t === "random()" ? null : n?.sortDirection,
			[e]: t
		}));
	}, f = (e) => {
		if (!s) return [];
		let t = g(e), n = [{
			value: "eq",
			label: "Equals"
		}, {
			value: "ne",
			label: "Not equals"
		}], r = [
			{
				value: "contains",
				label: "Contains"
			},
			{
				value: "notContains",
				label: "Not contains"
			},
			{
				value: "startsWith",
				label: "Starts with"
			},
			{
				value: "notStartsWith",
				label: "Not starts with"
			},
			{
				value: "endsWith",
				label: "Ends with"
			},
			{
				value: "notEndsWith",
				label: "Not ends with"
			}
		], i = [
			{
				value: "contains",
				label: "Contains"
			},
			{
				value: "notContains",
				label: "Not contains"
			},
			{
				value: "containsAll",
				label: "Contains all"
			},
			{
				value: "containsAny",
				label: "Contains any"
			},
			{
				value: "notContainsAny",
				label: "Not contains any"
			}
		], a = [
			{
				value: "lt",
				label: "Less than"
			},
			{
				value: "lte",
				label: "Less than or equal"
			},
			{
				value: "gt",
				label: "Greater than"
			},
			{
				value: "gte",
				label: "Greater than or equal"
			}
		], o = [
			{
				value: "before",
				label: "Before Date"
			},
			{
				value: "after",
				label: "After Date"
			},
			{
				value: "beforeNow",
				label: "Before Now"
			},
			{
				value: "afterNow",
				label: "After Now"
			}
		];
		switch (t) {
			case "array": return i;
			case "string": return [...n, ...r];
			case "number":
			case "integer": return [...n, ...a];
			case "boolean": return [{
				value: "eq",
				label: "Equals"
			}];
			case "date":
			case "datetime": return [...o, n[0]];
			default: return [
				...n,
				...r,
				...a,
				...o
			];
		}
	}, p = () => {
		let e = {
			field: "",
			op: "eq",
			value: ""
		};
		r((t) => {
			let n = t?.filters?.fields?.filter((e) => "field" in e) ?? [];
			return {
				...t,
				filters: {
					op: "and",
					fields: [...n, e]
				}
			};
		});
	}, m = (e) => {
		r((t) => {
			let n = t?.filters?.fields?.filter((e) => "field" in e) ?? [], r = n.filter((t, n) => n !== e);
			return {
				...t,
				filters: {
					op: "and",
					fields: r
				}
			};
		});
	}, h = (e, t, n) => {
		r((r) => {
			let i = [...r?.filters?.fields?.filter((e) => "field" in e) ?? []], a = { ...i[e] };
			if (t === "field") {
				let t = n ? f(n)[0]?.value ?? "eq" : "eq";
				i[e] = {
					field: n,
					op: t,
					value: ""
				};
			} else t === "op" ? i[e] = {
				...a,
				op: n,
				value: ""
			} : i[e] = {
				...a,
				[t]: n
			};
			return console.log("Updated filters:", i), {
				...r,
				filters: {
					op: "and",
					fields: i
				}
			};
		});
	}, g = (e) => {
		if (!s) return "string";
		let t = s.schema?.items?.properties?.[e];
		return t?.type === "string" && t.format === "date" ? "date" : t?.type === "string" && t.format === "date-time" ? "datetime" : t?.type ?? "string";
	}, _ = z((e) => {
		e.preventDefault(), e.stopPropagation(), console.log("Submitting query:", n), I.validate(v, n) ? (a(n), t?.()) : console.error("Query validation failed:", I.errors, n);
	}, [n]);
	return /* @__PURE__ */ (0, W.jsxs)("form", {
		onSubmit: _,
		className: "text-sm border border-gray-300 bg-gray-50 p-4 rounded-lg -mx-1 mt-3 shadow-sm",
		children: [
			/* @__PURE__ */ (0, W.jsx)("h3", {
				className: "font-bold text-base mb-3",
				children: e ? "Edit query" : "Create a new query"
			}),
			/* @__PURE__ */ (0, W.jsxs)("div", {
				className: "flex flex-col text-sm gap-4 flex-1 -mx-2.5 divide-y divide-gray-200",
				children: [
					/* @__PURE__ */ (0, W.jsxs)("div", {
						className: "flex justify-between gap-4 flex-1 items-center py-0.5 px-2.5",
						children: [/* @__PURE__ */ (0, W.jsxs)("div", {
							className: "flex flex-col gap-1 flex-1",
							children: [/* @__PURE__ */ (0, W.jsx)(k, {
								withIcon: !0,
								className: "font-medium",
								title: "Label",
								description: "Label displayed in the Editor"
							}), /* @__PURE__ */ (0, W.jsx)(A, {
								onInput: (e) => d("label", e.currentTarget.value),
								defaultValue: n?.label,
								maxLength: v.properties.label.maxLength,
								"aria-required": !0,
								placeholder: "Ex: Latest blog posts"
							})]
						}), /* @__PURE__ */ (0, W.jsxs)("div", {
							className: "flex flex-col gap-1 flex-1",
							children: [/* @__PURE__ */ (0, W.jsx)(k, {
								withIcon: !0,
								className: "font-medium",
								title: "Database",
								description: "Database to query"
							}), /* @__PURE__ */ (0, W.jsxs)(j, {
								"aria-required": !0,
								defaultValue: n?.datasourceId,
								size: "2",
								onValueChange: (e) => r((t) => ({
									...t ?? {},
									datasourceId: e,
									filters: {
										op: "and",
										fields: []
									}
								})),
								children: [/* @__PURE__ */ (0, W.jsx)(T, {
									radius: "medium",
									variant: "surface",
									placeholder: "Select a database",
									className: "!max-w-2/3 !mr-[1px]"
								}), /* @__PURE__ */ (0, W.jsx)(M, {
									position: "popper",
									children: o.map((e) => /* @__PURE__ */ (0, W.jsx)(D, {
										value: e.id,
										children: e.label
									}, e.id))
								})]
							})]
						})]
					}),
					c.length > 0 && /* @__PURE__ */ (0, W.jsxs)("div", {
						className: "flex flex-col gap-2 flex-1 justify-between pt-3 px-2.5",
						children: [/* @__PURE__ */ (0, W.jsxs)("div", {
							className: "flex flex-1 w-full justify-between items-center",
							children: [/* @__PURE__ */ (0, W.jsx)(k, {
								withIcon: !0,
								title: "Filters",
								className: "font-medium",
								description: "Add filters to narrow down your query"
							}), /* @__PURE__ */ (0, W.jsxs)(N, {
								type: "button",
								radius: "full",
								variant: "solid",
								size: "1",
								onClick: p,
								children: [/* @__PURE__ */ (0, W.jsx)(je, { className: "w-3 h-3" }), "Add Filter"]
							})]
						}), u.length > 0 && /* @__PURE__ */ (0, W.jsx)("div", {
							className: "flex flex-col gap-3 mt-1",
							children: u.map((e, t) => /* @__PURE__ */ (0, W.jsxs)(Pe, { children: [/* @__PURE__ */ (0, W.jsxs)("div", {
								className: "flex gap-x-3 gap-y-0.5 items-center",
								children: [
									/* @__PURE__ */ (0, W.jsx)("div", {
										className: "w-[200px] flex items-center gap-3 pr-1",
										children: /* @__PURE__ */ (0, W.jsxs)(j, {
											defaultValue: e.field,
											onValueChange: (e) => h(t, "field", e),
											children: [/* @__PURE__ */ (0, W.jsx)(T, {
												className: "!w-full",
												radius: "medium",
												variant: "surface",
												placeholder: "Select a field"
											}), /* @__PURE__ */ (0, W.jsx)(M, {
												position: "popper",
												children: /* @__PURE__ */ (0, W.jsx)(E, { children: c.map((e) => /* @__PURE__ */ (0, W.jsx)(D, {
													value: e.value,
													children: e.title
												}, e.value)) })
											})]
										})
									}),
									/* @__PURE__ */ (0, W.jsx)("div", {
										className: C("flex gap-2 items-center w-[120px]", !e.field && "hidden"),
										children: /* @__PURE__ */ (0, W.jsxs)(j, {
											defaultValue: e.op,
											size: "2",
											onValueChange: (e) => h(t, "op", e),
											disabled: !e.field,
											children: [/* @__PURE__ */ (0, W.jsx)(T, {
												radius: "medium",
												variant: "ghost",
												placeholder: "Select operator",
												className: "!flex-1 !mr-1"
											}), /* @__PURE__ */ (0, W.jsx)(M, {
												position: "popper",
												children: /* @__PURE__ */ (0, W.jsx)(E, { children: f(e.field).map((e) => /* @__PURE__ */ (0, W.jsx)(D, {
													value: e.value,
													children: e.label
												}, e.value)) })
											})]
										}, `operator-${t}-${e.field}`)
									}),
									g(e.field) === "date" || g(e.field) === "datetime" ? (e.op === "before" || e.op === "after" || e.op === "eq") && /* @__PURE__ */ (0, W.jsx)("div", {
										className: C("grow flex justify-end", !e.field && "hidden"),
										children: /* @__PURE__ */ (0, W.jsx)(A, {
											size: "2",
											type: g(e.field) === "datetime" ? "datetime-local" : "date",
											defaultValue: String(e.value || ""),
											onChange: (e) => h(t, "value", e.target.value),
											disabled: !e.field,
											className: "!w-full"
										})
									}) : /* @__PURE__ */ (0, W.jsx)("div", {
										className: C("grow flex justify-end", !e.field && "hidden"),
										children: g(e.field) === "number" || g(e.field) === "integer" ? /* @__PURE__ */ (0, W.jsx)(A, {
											type: "number",
											size: "2",
											defaultValue: String(e.value || ""),
											onChange: (e) => h(t, "value", Number(e.target.value)),
											placeholder: "Value",
											min: "1",
											disabled: !e.field,
											className: "!w-full"
										}) : g(e.field) === "boolean" ? /* @__PURE__ */ (0, W.jsxs)(le, {
											size: "1",
											defaultValue: String(e.value || "true"),
											onValueChange: (e) => h(t, "value", e === "true"),
											className: C("!mt-0.5 [&_.rt-SegmentedControlItemLabel]:(px-3)"),
											children: [/* @__PURE__ */ (0, W.jsx)(O, {
												value: "true",
												children: "True"
											}), /* @__PURE__ */ (0, W.jsx)(O, {
												value: "false",
												children: "False"
											})]
										}) : g(e.field) === "array" ? /* @__PURE__ */ (0, W.jsx)(ge, {
											initialValue: Array.isArray(e.value) ? e.value : [],
											onChange: (e) => h(t, "value", e),
											className: "!w-full",
											placeholder: "Add tags"
										}) : /* @__PURE__ */ (0, W.jsx)(A, {
											disabled: !e.field,
											defaultValue: String(e.value || ""),
											onChange: me((e) => h(t, "value", e.target.value), 400),
											placeholder: "Value",
											size: "2",
											className: "!w-full max-w-full"
										})
									}),
									/* @__PURE__ */ (0, W.jsx)(P, {
										size: "1",
										type: "button",
										variant: "ghost",
										className: "hover:(bg-red-100 text-red-800) !shrink-0 !ml-auto",
										onClick: () => m(t),
										children: /* @__PURE__ */ (0, W.jsx)(Ae, { size: 14 })
									})
								]
							}), t < u.length - 1 && /* @__PURE__ */ (0, W.jsx)("div", {
								className: "border-t border-dotted mx-auto w-2/3 border-gray-200 my-2 relative",
								children: /* @__PURE__ */ (0, W.jsx)("span", {
									className: "absolute left-1/2 -translate-x-1/2 -top-3 bg-gray-50 rounded-full px-2 py-1 inline-block text-xs text-gray-500",
									children: "And"
								})
							})] }, t))
						})]
					}),
					c.length > 0 && /* @__PURE__ */ (0, W.jsx)("div", {
						className: "flex flex-col gap-2 flex-1 justify-between pt-3 px-2.5",
						children: /* @__PURE__ */ (0, W.jsxs)("div", {
							className: "flex flex-1 w-full justify-between items-center",
							children: [/* @__PURE__ */ (0, W.jsx)(k, {
								title: "Parameters",
								className: "font-medium",
								withIcon: !0,
								description: "Optional fields that will be used as parameters when using the query. Only indexed fields can be used as parameters. Usually only one parameter is needed, but you can add multiple parameters if necessary. When specifying parameters, you will need to set a value for each parameter every time you use it."
							}), /* @__PURE__ */ (0, W.jsx)(_e, {
								options: c.map((e) => ({
									value: e.value,
									label: e.title
								})),
								initialValue: n?.parameters ?? [],
								isMulti: !0,
								onChange: (e) => r((t) => ({
									...t,
									parameters: e
								})),
								className: "!w-full min-w-fit max-w-[340px]",
								placeholder: "Add parameters (e.g. Slug, Id)"
							})]
						})
					}),
					n?.datasourceId && /* @__PURE__ */ (0, W.jsxs)("div", {
						className: "flex flex-1 gap-6 justify-between items-center pt-2.5 pb-1 px-2.5",
						children: [/* @__PURE__ */ (0, W.jsxs)("div", {
							className: "flex flex-col gap-1 flex-1 ",
							children: [/* @__PURE__ */ (0, W.jsx)(k, {
								className: "font-medium",
								title: "Order by",
								description: "Select a field to sort the results"
							}), /* @__PURE__ */ (0, W.jsxs)(j, {
								defaultValue: n?.sortField,
								size: "2",
								onValueChange: (e) => d("sortField", e),
								children: [/* @__PURE__ */ (0, W.jsx)(T, {
									radius: "medium",
									variant: "surface",
									className: "!mr-[1px] !mt-0.5",
									placeholder: "Select a field"
								}), /* @__PURE__ */ (0, W.jsxs)(M, {
									position: "popper",
									children: [
										/* @__PURE__ */ (0, W.jsx)(E, { children: l.map((e) => /* @__PURE__ */ (0, W.jsx)(D, {
											value: e.value,
											children: e.title
										}, e.value)) }),
										/* @__PURE__ */ (0, W.jsx)(xe, {}),
										/* @__PURE__ */ (0, W.jsx)(E, { children: /* @__PURE__ */ (0, W.jsx)(D, {
											value: "random()",
											children: "Random"
										}) })
									]
								})]
							})]
						}), /* @__PURE__ */ (0, W.jsxs)("div", {
							className: C("flex flex-col gap-1 flex-1", n?.sortField === "random()" && "opacity-40"),
							children: [/* @__PURE__ */ (0, W.jsx)(k, {
								className: "font-medium",
								title: "Direction",
								description: "Select the direction to sort the results"
							}), /* @__PURE__ */ (0, W.jsxs)(j, {
								disabled: n?.sortField === "random()",
								defaultValue: n?.sortDirection || "asc",
								size: "2",
								onValueChange: (e) => d("sortDirection", e),
								children: [/* @__PURE__ */ (0, W.jsx)(T, {
									radius: "medium",
									variant: "surface",
									placeholder: "Select direction",
									className: "!mr-[1px] !mt-0.5"
								}), /* @__PURE__ */ (0, W.jsx)(M, {
									position: "popper",
									children: /* @__PURE__ */ (0, W.jsxs)(E, { children: [/* @__PURE__ */ (0, W.jsx)(D, {
										value: "asc",
										children: "Ascending"
									}), /* @__PURE__ */ (0, W.jsx)(D, {
										value: "desc",
										children: "Descending"
									})] })
								})]
							})]
						})]
					}),
					n?.datasourceId && c.length > 0 && /* @__PURE__ */ (0, W.jsx)("div", {
						className: "flex flex-1 gap-6 justify-between items-center pt-2.5 pb-1 px-2.5",
						children: /* @__PURE__ */ (0, W.jsxs)("div", {
							className: "flex flex-col flex-1 gap-2",
							children: [/* @__PURE__ */ (0, W.jsx)(k, {
								className: "font-medium",
								title: "Max number of items to fetch",
								containerClassName: "!basis-0"
							}), /* @__PURE__ */ (0, W.jsx)(A, {
								type: "number",
								defaultValue: n?.limit?.toString() ?? "10",
								onChange: (e) => d("limit", parseInt(e.target.value) || 10),
								min: "1",
								max: "30",
								className: "!w-[40px]"
							})]
						})
					})
				]
			}),
			/* @__PURE__ */ (0, W.jsxs)("div", {
				className: "flex justify-end gap-2 mt-10",
				children: [/* @__PURE__ */ (0, W.jsx)(N, {
					type: "button",
					size: "2",
					color: "gray",
					variant: "soft",
					onClick: () => {
						i(), t?.();
					},
					children: "Cancel"
				}), /* @__PURE__ */ (0, W.jsx)(N, {
					disabled: I.validate(v, n) === !1,
					type: "submit",
					size: "2",
					children: "Save query"
				})]
			})
		]
	});
}
function Dt(e = !0, t) {
	let n = z((n) => {
		let r = typeof e == "function" ? e() : !0;
		if (r) return n.preventDefault(), t && (n.returnValue = t), t;
	}, [e, t]);
	B(() => {
		if (e) return window.addEventListener("beforeunload", n), () => window.removeEventListener("beforeunload", n);
	}, [e, n]);
}
const Ot = R(() => import("./chunks/Tour.D4cdITsh.js")), kt = R(() => import("./chunks/NavBar.juUtZ3mA.js")), At = R(() => import("./chunks/Chat.Cg21XgE0.js")), jt = R(() => import("./chunks/EditablePage.BdRzcYsK.js")), Mt = R(() => import("./Page.js")), $ = R(() => import("./chunks/DeviceFrame.BtzsDnbI.js")), Nt = R(() => import("./chunks/Panel.1Qf6eayN.js"));
function Pt(e) {
	let a = V(null), o = b(), c = r(), f = t(), p = d(), { panelPosition: m } = s(), h = _(), g = ne(), v = x(), { setDraggingBrickType: y, toggleDebugMode: te, hidePanel: re } = i(), ie = l(), ae = u(), ce = ut(), w = n(), T = V(null);
	return ze(), st(), Dt(() => !!o.dirty, "You have unsaved changes. Are you sure you want to leave?"), B(() => {
		let e = o.previewTheme ?? o.theme;
		e && oe(S(Ce(e)));
	}, [o.previewTheme, o.theme]), c ? /* @__PURE__ */ (0, W.jsx)(we, {
		onDragStart: (e, t) => {
			let { operation: n } = e;
			if (n.source?.type === "library") {
				let e = n.source.data.manifest.type;
				y(e);
				return;
			}
			if (console.log(`Started dragging ${n.source?.id}`), n.source?.id) {
				let e = document.getElementById(n.source.id);
				if (!e) return;
				console.log(`adding class ${n.source.id}`), e?.classList.add("moving"), e.style.setProperty("box-shadow", "0 4px 8px rgba(0, 0, 0, 0.2)", "important"), e.style.setProperty("outline", "2px solid var(--violet-8)", "important"), e.style.setProperty("outline-offset", "0px", "important");
				let t = window.getComputedStyle(e);
				t.getPropertyValue("background-color") === "rgba(0, 0, 0, 0)" && (console.log("Changing background color to upstart-200"), e.style.setProperty("background-color", "var(--violet-a5)", "important"));
			}
		},
		onDragOver: (e, t) => {
			let { operation: n } = e, r = n.source?.type === "library";
			if (n.canceled || !n.target) return;
			if (n.target?.data?.manifest?.isContainer && n.activatorEvent?.metaKey) {
				console.log("operation.activatorEvent", n.activatorEvent), console.error("Dropping over a container, disable reordering"), e.preventDefault();
				return;
			}
			let i = p.reduce((e, t) => (e[t.id] = t.bricks.filter((e) => !v.getParentBrick(e.id)).map((e) => e.id), e), {});
			r && (i.$library$ = T.current ? [] : [n.source.id]);
			let a = St(i, e);
			if (Ne(i, a)) console.debug("Items are equal, no changes made");
			else for (let e of p) if (!Ne(i[e.id], a[e.id])) {
				console.log("Rebuilding section", e.id);
				let t = {
					...e,
					bricks: a[e.id].map((t, i) => {
						if (r && t === n.source.id && !v.getBrick(t)) {
							let t = ee(n.source.data?.manifest.type, !0);
							return T.current = t.id, v.addBrick(t, e.id, i, null), t;
						}
						return v.getBrick(t);
					})
				};
				v.updateSection(e.id, t);
			}
		},
		onDragEnd: (e) => {
			console.log("Ended dragging", e);
			let { operation: { source: t } } = e;
			T.current && v.updateBrickProps(T.current, { ghost: !1 }), y(null), T.current = null, t?.id && setTimeout(() => {
				let e = document.getElementById(t.id);
				e && (e.classList.remove("moving"), e.style.removeProperty("box-shadow"), e.style.removeProperty("outline"), e.style.removeProperty("outline-offset"), e.style.removeProperty("background-color"));
			}, 200);
		},
		children: /* @__PURE__ */ (0, W.jsxs)("div", {
			id: "editor",
			className: C("grid relative transition-all mx-auto w-full", Ft(g, f), "min-h-[100dvh] max-h-[100dvh]", g.isReady === !1 && S({ background: "linear-gradient(120deg,\n              oklab(from #9291e7 l a b / 0.65),\n              oklab(from #7270c6 l a b / 0.65),\n              oklab(from #c050c2 l a b / 0.65),\n              oklab(from #ef50a2 l a b / 0.65),\n              oklab(from #ff6285 l a b / 0.65),\n              oklab(from #ff806b l a b / 0.65),\n              oklab(from #ffa25a l a b / 0.65),\n              oklab(from #ffc358 l a b / 0.65)\n          )" }), g.isReady === !1 && "transition-all duration-500 ease-in-out"),
			...e,
			ref: a,
			children: [
				p.length > 0 && g.isReady && /* @__PURE__ */ (0, W.jsx)(L, { children: /* @__PURE__ */ (0, W.jsx)(Ot, {}) }),
				/* @__PURE__ */ (0, W.jsx)(L, { children: /* @__PURE__ */ (0, W.jsx)(kt, {}) }),
				f && /* @__PURE__ */ (0, W.jsx)(L, { children: /* @__PURE__ */ (0, W.jsx)(At, {}) }),
				/* @__PURE__ */ (0, W.jsxs)(L, { children: [/* @__PURE__ */ (0, W.jsx)(wt, {}), /* @__PURE__ */ (0, W.jsx)(Nt, {})] }),
				/* @__PURE__ */ (0, W.jsxs)("main", {
					className: C("flex-1 flex place-content-center z-40 overflow-x-auto overscroll-none", g.isReady === !1 && "!hidden", S({
						gridArea: "main",
						scrollbarColor: "var(--violet-4) var(--violet-2)",
						scrollBehavior: "smooth",
						scrollbarGutter: "stable",
						scrollbarWidth: m === "left" ? "thin" : "none",
						"&:hover": { scrollbarColor: "var(--violet-7) var(--violet-3)" }
					})),
					children: [
						g.isReady && /* @__PURE__ */ (0, W.jsx)(L, { children: /* @__PURE__ */ (0, W.jsxs)($, { children: [/* @__PURE__ */ (0, W.jsx)(jt, {}), o.previewTheme && /* @__PURE__ */ (0, W.jsx)(It, {})] }) }),
						!g.isReady && (h.length > 0 ? /* @__PURE__ */ (0, W.jsx)($, { children: /* @__PURE__ */ (0, W.jsx)(ct, { themes: h }) }) : /* @__PURE__ */ (0, W.jsx)($, { children: /* @__PURE__ */ (0, W.jsx)(lt, {}) })),
						/* @__PURE__ */ (0, W.jsx)(se, { toastOptions: {
							position: "bottom-center",
							style: {
								background: "rgba(0, 0, 0, 0.85)",
								color: "white",
								fontSize: "0.85rem",
								fontWeight: "500"
							},
							className: C("last:mb-1 px-1 py-1 rounded-lg"),
							error: { style: { background: "#880808" } }
						} }),
						ce && /* @__PURE__ */ (0, W.jsxs)("div", {
							className: "fixed flex max-w-[548px] items-center divide-x divide-gray-300 bottom-0 right-6 p-2 text-xs text-gray-500 bg-gray-100 dark:bg-dark-800 z-[19999] rounded-t-md",
							style: { boxShadow: "0 -2px 4px rgba(0, 0, 0, 0.1), -2px 0 4px rgba(0, 0, 0, 0.1)" },
							children: [
								/* @__PURE__ */ (0, W.jsxs)("div", {
									className: "px-2",
									children: ["Selected brick: ", ie ?? "none"]
								}),
								/* @__PURE__ */ (0, W.jsxs)("div", {
									className: "px-2",
									children: ["Selected section: ", ae ?? "none"]
								}),
								/* @__PURE__ */ (0, W.jsxs)("div", {
									className: "flex items-center gap-1 px-2",
									children: [/* @__PURE__ */ (0, W.jsx)(be, {
										defaultChecked: w,
										onCheckedChange: te,
										size: "1",
										id: "debug-mode"
									}), /* @__PURE__ */ (0, W.jsxs)("label", {
										htmlFor: "debug-mode",
										className: "cursor-pointer select-none",
										children: [
											"Debug mode",
											" ",
											/* @__PURE__ */ (0, W.jsx)("b", {
												className: C("font-semibold", w ? "text-upstart-600" : "text-gray-500"),
												children: w ? "on" : "off"
											})
										]
									})]
								})
							]
						})
					]
				})
			]
		})
	}) : /* @__PURE__ */ (0, W.jsx)("div", {
		className: "@container",
		children: /* @__PURE__ */ (0, W.jsx)(L, { children: /* @__PURE__ */ (0, W.jsx)(Mt, {
			page: {
				...o,
				attributes: o.pageAttributes
			},
			site: {
				...o,
				attributes: o.siteAttributes
			}
		}) })
	});
}
function Ft(e, t) {
	return S({
		gridTemplateAreas: t ? "\"navbar navbar\" \"chat main\"" : "\"navbar\" \"main\"",
		gridTemplateRows: "64px 1fr",
		gridTemplateColumns: e.isReady === !1 ? "1fr 0px" : t ? "360px 1fr" : "1fr"
	});
}
function It() {
	let { validatePreviewTheme: e } = x();
	return /* @__PURE__ */ (0, W.jsx)("div", {
		className: "fixed bottom-0 left-0 right-0 flex justify-center items-center z-[9999]",
		children: /* @__PURE__ */ (0, W.jsxs)("div", {
			className: "p-3 pb-2 bg-black/70 backdrop-blur-md rounded-t-lg max-w-fit flex gap-2 shadow-xl",
			children: [/* @__PURE__ */ (0, W.jsx)(N, {
				variant: "solid",
				color: "gray",
				onClick: () => e(!1),
				children: "Revert"
			}), /* @__PURE__ */ (0, W.jsx)(N, {
				onClick: () => e(!0),
				variant: "solid",
				children: "Accept theme"
			})]
		})
	});
}
export { Pt as default };

//# sourceMappingURL=Editor.js.map