import { A as e, B as t, C as n, D as r, E as i, F as a, G as o, H as s, I as c, J as l, K as u, L as d, M as f, N as p, O as m, Q as ee, S as h, T as te, U as ne, V as g, W as re, Y as ie, _ as ae, b as oe, c as _, d as se, f as ce, g as le, h as ue, j as v, k as de, l as fe, m as pe, n as me, o as he, p as y, q as b, s as x, t as ge, u as _e, v as ve, w as ye, x as S, y as be, z as C } from "./Parser-UQbHWtve.js";
import { useCallback as xe, useInsertionEffect as Se, useRef as Ce } from "react";
import { capitalize as we, defaultTo as Te, get as Ee, isPlainObject as De, throttle as Oe } from "lodash-es";
import { differenceInMinutes as ke, format as w, formatDistanceToNow as Ae, formatRelative as je, isSameDay as Me, isThisWeek as Ne, isThisYear as Pe, isToday as T, isTomorrow as Fe, isYesterday as Ie } from "date-fns";
//#region src/components-core/utils/misc.ts
function Le(e, t) {
	return Object.entries(e).reduce(([e, n], [r, i]) => t(r, i) ? [{
		...e,
		[r]: i
	}, n] : [e, {
		...n,
		[r]: i
	}], [{}, {}]);
}
var Re = 1;
function ze() {
	return `$qid_${Re++}`;
}
function Be() {
	return crypto?.randomUUID ? crypto?.randomUUID() : "10000000-1000-4000-8000-100000000000".replace(/[018]/g, (e) => (e ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> e / 4).toString(16));
}
function Ve(e) {
	let t = e + "=", n = document.cookie.split(";");
	for (let e = 0; e < n.length; e++) {
		let r = n[e];
		for (; r.charAt(0) === " ";) r = r.substring(1, r.length);
		if (r.indexOf(t) === 0) return r.substring(t.length, r.length);
	}
	return null;
}
var He = (e) => new Promise((t) => setTimeout(t, e));
function Ue(e) {
	return e[0].toUpperCase() + e.substring(1);
}
function We(e) {
	if (typeof e == "object") for (let t in e) e[t] === null || e[t] === void 0 ? delete e[t] : We(e[t]);
}
var Ge = (e) => {
	let t = Ce(e);
	return Se(() => {
		t.current = e;
	}, [e]), xe((...e) => {
		let n = t.current;
		return n?.(...e);
	}, [t]);
};
function Ke(e, t = !1, n = 1) {
	let r = t ? 1e3 : 1024;
	if (Math.abs(e) < r) return e + " B";
	let i = t ? [
		"kB",
		"MB",
		"GB",
		"TB",
		"PB",
		"EB",
		"ZB",
		"YB"
	] : [
		"KiB",
		"MiB",
		"GiB",
		"TiB",
		"PiB",
		"EiB",
		"ZiB",
		"YiB"
	], a = -1, o = 10 ** n;
	do
		e /= r, ++a;
	while (Math.round(Math.abs(e) * o) / o >= r && a < i.length - 1);
	return e.toFixed(n) + " " + i[a];
}
function qe(e, t, n) {
	let r = Ae(new Date(e), { includeSeconds: !0 }), i = t || r;
	return n && r.includes(n) ? i : r;
}
function Je(e, t) {
	let n = e?.includes(".") ? e?.split(".").pop()?.toLowerCase() : void 0;
	if (!t) return n;
	let r = Ye.get(t.split(";")[0] || "");
	return !n && r ? r : n === r ? n : void 0;
}
var Ye = new Map([
	["text/html", "html"],
	["text/css", "css"],
	["text/xml", "xml"],
	["image/gif", "gif"],
	["image/jpeg", "jpg"],
	["application/x-javascript", "js"],
	["application/atom+xml", "atom"],
	["application/rss+xml", "rss"],
	["text/mathml", "mml"],
	["text/plain", "txt"],
	["text/vnd.sun.j2me.app-descriptor", "jad"],
	["text/vnd.wap.wml", "wml"],
	["text/x-component", "htc"],
	["image/png", "png"],
	["image/tiff", "tif"],
	["image/vnd.wap.wbmp", "wbmp"],
	["image/x-icon", "ico"],
	["image/x-jng", "jng"],
	["image/x-ms-bmp", "bmp"],
	["image/svg+xml", "svg"],
	["image/webp", "webp"],
	["application/java-archive", "jar"],
	["application/mac-binhex40", "hqx"],
	["application/msword", "doc"],
	["application/pdf", "pdf"],
	["application/postscript", "ps"],
	["application/rtf", "rtf"],
	["application/vnd.ms-excel", "xls"],
	["application/vnd.ms-powerpoint", "ppt"],
	["application/vnd.wap.wmlc", "wmlc"],
	["application/vnd.google-earth.kml+xml", "kml"],
	["application/vnd.google-earth.kmz", "kmz"],
	["application/x-7z-compressed", "7z"],
	["application/x-cocoa", "cco"],
	["application/x-java-archive-diff", "jardiff"],
	["application/x-java-jnlp-file", "jnlp"],
	["application/x-makeself", "run"],
	["application/x-perl", "pl"],
	["application/x-pilot", "prc"],
	["application/x-rar-compressed", "rar"],
	["application/x-redhat-package-manager", "rpm"],
	["application/x-sea", "sea"],
	["application/x-shockwave-flash", "swf"],
	["application/x-stuffit", "sit"],
	["application/x-tcl", "tcl"],
	["application/x-x509-ca-cert", "pem"],
	["application/x-xpinstall", "xpi"],
	["application/xhtml+xml", "xhtml"],
	["application/zip", "zip"],
	["application/octet-stream", "exe"],
	["audio/midi", "mid"],
	["audio/mpeg", "mp3"],
	["audio/ogg", "ogg"],
	["audio/x-realaudio", "ra"],
	["video/3gpp", "3gpp"],
	["video/mpeg", "mpeg"],
	["video/quicktime", "mov"],
	["video/x-flv", "flv"],
	["video/x-mng", "mng"],
	["video/x-ms-asf", "asf"],
	["video/x-ms-wmv", "wmv"],
	["video/x-msvideo", "avi"],
	["video/mp4", "mp4"]
]);
function Xe(e, t) {
	return new Promise((n) => setTimeout(async () => {
		await t?.(), n?.();
	}, e));
}
function Ze(e) {
	if (!e) return;
	if (e.startsWith("http://") || e.startsWith("https://") || typeof window > "u") return e;
	let t = window.__PUBLIC_PATH || "";
	return t ? `${t.endsWith("/") ? t.slice(0, -1) : t}/${e.startsWith("/") ? e.slice(1) : e}` : e;
}
function Qe(e) {
	return typeof e != "string";
}
async function $e(e, ...t) {
	if (!t.length) return e;
	let n = 0, r = [];
	for (; n < t.length;) {
		let e = t[n], i;
		if (typeof e == "string") i = { mapperFn: (t) => t[e] };
		else if (typeof e == "function") i = { mapperFn: (t) => e(t) };
		else {
			n++;
			continue;
		}
		n++, n < t.length && typeof t[n] == "boolean" && (i.desc = !0, n++), r.push(i);
	}
	let i = [];
	for (let t of r) {
		let n = /* @__PURE__ */ new Map();
		for (let r = 0; r < e.length; r++) n.set(e[r], await t.mapperFn(e[r]));
		i.push(n);
	}
	return e.sort((e, t) => {
		for (let n = 0; n < r.length; n++) {
			let a = r[n], o = i[n].get(e), s = i[n].get(t);
			if (o !== s) return o < s ? a.desc ? 1 : -1 : a.desc ? -1 : 1;
		}
		return 0;
	});
}
var et = (e, t) => tt(e, t);
function tt(e, t) {
	let n = Array.isArray(e), r = Array.isArray(t);
	return typeof e == "string" || typeof t == "string" ? e === t : n === r ? n && r ? nt(e, t) : rt(e, t) : !1;
}
function nt(e, t) {
	if (e === t) return !0;
	if (!e || !t) return !1;
	let n = e.length;
	if (t.length !== n) return !1;
	for (let r = 0; r < n; r++) if (e[r] !== t[r]) return !1;
	return !0;
}
function rt(e, t) {
	if (e === t) return !0;
	if (!e || !t) return !1;
	let n = Reflect.ownKeys(e), r = Reflect.ownKeys(t), i = n.length;
	if (r.length !== i) return !1;
	for (let r = 0; r < i; r++) {
		let i = n[r];
		if (e[i] !== t[i] || !Object.prototype.hasOwnProperty.call(t, i)) return !1;
	}
	return !0;
}
var it = (e, t) => {
	let n = {};
	return t.forEach((t) => {
		Ee(e, t) !== void 0 && (n[t] = Ee(e, t));
	}), n;
}, at = (e) => Object(e) !== e;
function ot(e) {
	return e ? Ke(e) : "-";
}
function st(e, t) {
	return Je(e, t);
}
function ct(e, t, n) {
	return e === 1 ? `${e} ${t}` : `${e} ${n}`;
}
function lt(e, t, n) {
	return (e ?? []).reduce((e, r) => (e[r[t]] = r[n], e), {});
}
function ut(e, t, n) {
	return (e ?? []).find((e) => e[t || ""] === n);
}
function dt(e) {
	return !Array.isArray(e) || !e || !e.length ? [] : Array.from(new Set(e));
}
function ft(e, t, n) {
	let r = Oe((t, n, r) => {
		e(...r).then(t).catch(n);
	}, t, n);
	return (...e) => new Promise((t, n) => {
		r(t, n, e);
	});
}
var E = /* @__PURE__ */ new Map();
function pt(e, t, ...n) {
	let r = t.toString(), i = E.get(r);
	i !== void 0 && clearTimeout(i.timeoutId);
	let a = setTimeout(() => {
		let e = E.get(r);
		e && (t(...e.args), E.delete(r));
	}, e);
	E.set(r, {
		timeoutId: a,
		args: n
	});
}
//#endregion
//#region src/components-core/EngineError.ts
var D = class e extends Error {
	constructor(t) {
		super(t), Object.setPrototypeOf(this, e.prototype);
	}
}, mt = class e extends D {
	constructor(t, n) {
		let r = t?.message || t?.error?.message || t?.title || (typeof t?.error == "string" ? t.error : null) || (typeof t == "string" ? t : null) || "Unknown error", i = t?.details || t?.detail || t?.error?.details || t?.errors || (t?.error && typeof t.error == "object" ? t.error : null) || null, a = i ? t?.issues ? {
			...i,
			issues: t.issues
		} : i : t?.issues ? { issues: t.issues } : null;
		super(r), this.info = t, this.errorCategory = "GenericBackendError", this.message = r, this.details = a, this.statusCode = n, this.response = t, Object.setPrototypeOf(this, e.prototype);
	}
}, ht = class e extends D {
	constructor(t, n, r) {
		t = `Parser Error: ${t}`, super(t), this.source = n, this.position = r, this.errorCategory = "ScriptParserError", Object.setPrototypeOf(this, e.prototype);
	}
}, gt = class e extends D {
	constructor(t, n) {
		super(t), this.source = n, this.errorCategory = "StatementExecutionError", Object.setPrototypeOf(this, e.prototype);
	}
}, _t = class e extends D {
	constructor() {
		super("Must be a component definition, cannot use dynamic children here..."), this.errorCategory = "NotAComponentError", Object.setPrototypeOf(this, e.prototype);
	}
}, O = class e extends D {
	constructor(t) {
		let n = typeof t == "string" ? t : t?.message || "Error without message";
		super(n), this.errorObject = t, this.errorCategory = "ThrowStatementError", this.message = n, Object.setPrototypeOf(this, e.prototype);
	}
};
function vt(e) {
	return {
		statusCode: e.statusCode || 500,
		message: e.message || "An error occurred",
		details: e.details || {},
		response: e.info
	};
}
//#endregion
//#region src/components-core/script-runner/bannedFunctions.ts
var yt = class extends Error {
	constructor(e, t) {
		super(`DOM API '${e}' is not allowed in XMLUI expressions.${t ? ` ${t}` : ""}`), this.api = e, this.helpText = t, this.name = "BannedApiError";
	}
};
function bt(e) {
	if (e === void 0) return { banned: !1 };
	let t = xt.find((t) => t.func === e);
	return t ? {
		banned: !0,
		func: t.func,
		help: t.help
	} : { banned: !1 };
}
var xt = [
	{ func: globalThis.cancelAnimationFrame },
	{ func: globalThis.cancelIdleCallback },
	{ func: globalThis.clearInterval },
	{ func: globalThis.clearImmediate },
	{ func: globalThis.clearTimeout },
	{ func: globalThis.eval },
	{ func: globalThis.queueMicrotask },
	{ func: globalThis.requestAnimationFrame },
	{ func: globalThis.requestIdleCallback },
	{ func: globalThis.setImmediate },
	{ func: globalThis.setInterval },
	{
		func: globalThis.setTimeout,
		help: "Use 'delay'"
	},
	{
		func: globalThis.Function,
		help: "Dynamic code execution is not allowed."
	},
	...typeof WebAssembly < "u" ? [
		{
			func: WebAssembly.compile,
			help: "WebAssembly execution is not allowed."
		},
		{
			func: WebAssembly.instantiate,
			help: "WebAssembly execution is not allowed."
		},
		{
			func: WebAssembly.compileStreaming,
			help: "WebAssembly execution is not allowed."
		},
		{
			func: WebAssembly.instantiateStreaming,
			help: "WebAssembly execution is not allowed."
		},
		{ func: WebAssembly.Module },
		{ func: WebAssembly.Instance }
	] : []
], St = new Set(/* @__PURE__ */ "MutationObserver.ResizeObserver.IntersectionObserver.PerformanceObserver.Range.Selection.getSelection.Worker.SharedWorker.MessageChannel.MessagePort.BroadcastChannel.SharedArrayBuffer.Atomics.localStorage.sessionStorage.indexedDB.caches.cookieStore.PushManager.PeriodicSyncManager.BackgroundFetchManager.Notification.open.close.stop.print.focus.blur.history.location.XMLHttpRequest.EventSource.WebSocket.crypto.performance.console.fetch".split(".")), Ct = new Map([
	["localStorage", "Use AppState.get/set() for persistent key-value storage."],
	["sessionStorage", "Use AppState.get/set() for session-scoped storage."],
	["location", "Use navigate() instead of window.location."],
	["history", "Use navigate() to control the browser history."],
	["open", "Use App.openExternal() to open URLs in a new tab."],
	["console", "Use Log.*() functions for tracing."],
	["crypto", "Use App.randomBytes() for random data (available in Phase 2.4)."],
	["performance", "Use App.now() / App.mark() (available in Phase 2.5)."],
	["XMLHttpRequest", "Use DataSource or APICall for network requests."],
	["WebSocket", "Use the WebSocket component for real-time connections."],
	["EventSource", "Use the EventSource component for server-sent events."],
	["fetch", "Use App.fetch() for managed HTTP requests with CSRF protection and origin allowlist support."]
]), wt = new Set([
	"body",
	"documentElement",
	"head",
	"querySelector",
	"querySelectorAll",
	"getElementById",
	"getElementsByClassName",
	"getElementsByTagName",
	"getElementsByName",
	"createElement",
	"createElementNS",
	"createTextNode",
	"createDocumentFragment",
	"createRange",
	"write",
	"writeln",
	"execCommand",
	"domain",
	"cookie",
	"title"
]), Tt = new Map([
	["cookie", "Use AppState.get/set() for persistent storage."],
	["title", "Set the page title via the Page component's title prop."],
	["body", "Use XMLUI component props to modify the DOM through React instead of direct access."]
]), Et = new Set([
	"serviceWorker",
	"storage",
	"geolocation",
	"mediaDevices",
	"clipboard",
	"permissions",
	"bluetooth",
	"usb",
	"serial",
	"hid",
	"credentials",
	"locks",
	"sendBeacon"
]), Dt = new Set([
	"userAgent",
	"userAgentData",
	"platform",
	"hardwareConcurrency",
	"deviceMemory",
	"connection"
]), Ot = new Map([
	["userAgent", "Use App.environment.isMobile for device detection."],
	["userAgentData", "Use App.environment.isMobile for device detection."],
	["platform", "Use App.environment for curated environment properties."],
	["hardwareConcurrency", "Hardware fingerprinting is not permitted from expressions."],
	["deviceMemory", "Hardware fingerprinting is not permitted from expressions."],
	["connection", "Use App.environment for curated environment properties."]
]), kt = new Map([
	["clipboard", "Use Clipboard.copy() for writing to the clipboard (available in Phase 2.2)."],
	["geolocation", "Use the Geolocation component (planned)."],
	["sendBeacon", "Use APICall for fire-and-forget HTTP requests."]
]), At = new Set([
	"innerHTML",
	"outerHTML",
	"insertAdjacentHTML",
	"insertAdjacentElement",
	"insertAdjacentText",
	"setAttribute",
	"removeAttribute",
	"setAttributeNS",
	"appendChild",
	"insertBefore",
	"replaceChild",
	"removeChild",
	"replaceWith",
	"before",
	"after",
	"prepend",
	"append"
]);
function k(e, t) {
	if (e == null || typeof t != "string") return { banned: !1 };
	if ((typeof globalThis < "u" && e === globalThis || typeof window < "u" && e === window) && St.has(t)) return {
		banned: !0,
		api: `window.${t}`,
		help: Ct.get(t)
	};
	if (typeof document < "u" && e === document && wt.has(t)) return {
		banned: !0,
		api: `document.${t}`,
		help: Tt.get(t)
	};
	if (typeof navigator < "u" && e === navigator) {
		if (Et.has(t)) return {
			banned: !0,
			api: `navigator.${t}`,
			help: kt.get(t)
		};
		if (Dt.has(t)) return {
			banned: !0,
			api: `navigator.${t}`,
			help: Ot.get(t)
		};
	}
	return typeof Element < "u" && e instanceof Element && At.has(t) ? {
		banned: !0,
		api: `Element.${t}`,
		help: "Use component props to update the DOM instead of direct mutation."
	} : { banned: !1 };
}
//#endregion
//#region src/components-core/script-runner/eval-tree-common.ts
function A(e, t) {
	if (!e.banned || e.api === "window.console" && t?.allowConsole !== !1) return;
	let n = t?.strictDomSandbox ?? !1, r = t?.sandboxWarnLogger, i = `DOM API access to '${e.api}' is not allowed in XMLUI expressions.${e.help ? ` ${e.help}` : ""}`;
	if (n) throw new yt(e.api ?? "unknown", e.help);
	console.warn(`[XMLUI sandbox] ${i}`), r?.({
		api: e.api,
		help: e.help,
		text: i
	});
}
function j(e, t) {
	return t?.valueCache?.get(e)?.value;
}
function M(e, t, n) {
	n.valueCache ??= /* @__PURE__ */ new Map(), n.valueCache.set(e, { value: t });
}
function jt(e) {
	return e && typeof e.then == "function";
}
function Mt(e, t, n) {
	return M(t, { value: t.value }, n), e.push(t.value), t.value;
}
function N(e, t, n) {
	let r, i;
	{
		let a = n ?? t.mainThread;
		for (; a && !i;) {
			if (a.blocks) for (let t = a.blocks.length - 1; t >= 0; t--) {
				let n = a.blocks[t]?.vars;
				if (n && e.name in n) {
					i = n, r = "block";
					break;
				}
			}
			if (i) break;
			if (a.closures) for (let t = a.closures.length - 1; t >= 0; t--) {
				let n = a.closures[t]?.vars;
				if (n && e.name in n) {
					i = n, r = "block";
					break;
				}
			}
			if (i) break;
			a = a.parent;
		}
	}
	return i || (t.localContext && e.name in t.localContext ? (i = t.localContext, r = "localContext") : t.appContext?.[e.name] === void 0 ? (i = globalThis, r = "global") : (i = t.appContext, r = "app")), {
		type: r,
		scope: i
	};
}
function Nt(e, t, n, r) {
	let i, a = N(t, n, r), o = a.scope, s = t.name;
	return a.type === "global" && A(k(o, s), n.options), i = o[s], M(t, {
		valueScope: o,
		valueIndex: s,
		value: i
	}, r), e.push(i), i;
}
function P(e, t, n) {
	switch (e.type) {
		case m: return {
			type: N(e, t, n).type,
			name: e.name
		};
		case f: return P(e.obj, t, n);
		case ue: return P(e.obj, t, n);
	}
	return null;
}
function Pt(e, t, n, r) {
	let i = j(t.obj, r)?.value;
	A(k(i, t.member), n.options);
	let a = t.opt || n.options?.defaultToOptionalMemberAccess ? i?.[t.member] : i[t.member];
	return M(t, {
		valueScope: i,
		valueIndex: t.member,
		value: a
	}, r), e.push(a), a;
}
function Ft(e, t, n, r) {
	let i = j(t.obj, r)?.value, a = j(t.member, r)?.value;
	A(k(i, a), n.options);
	let o = n.options?.defaultToOptionalMemberAccess ? i?.[a] : i[a];
	return M(t, {
		valueScope: i,
		valueIndex: a,
		value: o
	}, r), e.push(o), o;
}
function It(e, t, n, r) {
	let i, a = j(e.expr, r), o = a?.value;
	switch (e.op) {
		case "typeof":
			i = typeof o;
			break;
		case "delete":
			i = a.valueScope && a.valueIndex ? delete a.valueScope[a.valueIndex] : !1;
			break;
		case "+":
			i = o;
			break;
		case "-":
			i = -o;
			break;
		case "!":
			i = !o;
			break;
		case "~":
			i = ~o;
			break;
		default: throw Error(`Unknown unary operator: ${e.op}`);
	}
	return M(e, { value: i }, r), t.push(i), i;
}
function Lt(e, t, n, r) {
	let i, a = j(e.left, r)?.value, o = j(e.right, r)?.value;
	switch (e.op) {
		case "**":
			i = a ** o;
			break;
		case "*":
			i = a * o;
			break;
		case "/":
			i = a / o;
			break;
		case "%":
			i = a % o;
			break;
		case "+":
			i = a + o;
			break;
		case "-":
			i = a - o;
			break;
		case ">>":
			i = a >> o;
			break;
		case ">>>":
			i = a >>> o;
			break;
		case "<<":
			i = a << o;
			break;
		case "<":
			i = a < o;
			break;
		case "<=":
			i = a <= o;
			break;
		case ">":
			i = a > o;
			break;
		case ">=":
			i = a >= o;
			break;
		case "in":
			i = a in o;
			break;
		case "instanceof":
			i = a instanceof o;
			break;
		case "==":
			i = a == o;
			break;
		case "!=":
			i = a != o;
			break;
		case "===":
			i = a === o;
			break;
		case "!==":
			i = a !== o;
			break;
		case "&":
			i = a & o;
			break;
		case "^":
			i = a ^ o;
			break;
		case "|":
			i = a | o;
			break;
		case "&&":
			i = a && o;
			break;
		case "||":
			i = a || o;
			break;
		case "??":
			i = a ?? o;
			break;
		default: throw Error(`Unknown binary operator: ${e.op}`);
	}
	return M(e, { value: i }, r), t.push(i), i;
}
function Rt(e, t, n, r) {
	let i = j(t.leftValue, r), a = j(t.expr, r)?.value;
	if (!i.valueScope || i.valueIndex === void 0 || i.valueIndex === null) throw Error(`Evaluation of ${t.op} requires a left-hand value.`);
	let o = i.valueScope, s = i.valueIndex;
	if (typeof o != "object" || !o) throw Error("Unknown left-hand value");
	if (t.leftValue.type === m && Ht(t.leftValue.name, r)) throw Error("A const variable cannot be modified");
	if (o === globalThis && !(s in o)) throw Error(`Left value variable (${s}) not found in the scope.`);
	switch (A(k(o, s), n.options), e.pop(), t.op) {
		case "=":
			o[s] = a;
			break;
		case "+=":
			o[s] += a;
			break;
		case "-=":
			o[s] -= a;
			break;
		case "**=":
			o[s] **= a;
			break;
		case "*=":
			o[s] *= a;
			break;
		case "/=":
			o[s] /= a;
			break;
		case "%=":
			o[s] %= a;
			break;
		case "<<=":
			o[s] <<= a;
			break;
		case ">>=":
			o[s] >>= a;
			break;
		case ">>>=":
			o[s] >>>= a;
			break;
		case "&=":
			o[s] &= a;
			break;
		case "^=":
			o[s] ^= a;
			break;
		case "|=":
			o[s] |= a;
			break;
		case "&&=":
			o[s] &&= a;
			break;
		case "||=":
			o[s] ||= a;
			break;
		case "??=":
			o[s] += a;
			break;
	}
	let c = o[s];
	return M(t, { value: c }, r), e.push(c), c;
}
function zt(e, t, n, r) {
	let i = j(t.expr, r);
	if (!i.valueScope || i.valueIndex === void 0) throw Error(`Evaluation of ${t.op} requires a left-hand value.`);
	if (i.valueScope === globalThis && !(i.valueIndex in i.valueScope)) throw Error(`Left value variable (${i.valueIndex}) not found in the scope.`);
	if (t.expr.type === m && Ht(t.expr.name, r)) throw Error("A const variable cannot be modified");
	let a = t.op === "++" ? t.type === d ? ++i.valueScope[i.valueIndex] : i.valueScope[i.valueIndex]++ : t.type === d ? --i.valueScope[i.valueIndex] : i.valueScope[i.valueIndex]--;
	return M(t, { value: a }, r), e.push(a), a;
}
function Bt(e, t, n) {
	if (t.async) throw Error("XMLUI does not support async arrow functions.");
	let r = {
		...t,
		_ARROW_EXPR_: !0,
		closureContext: Vt(n)
	};
	return M(t, { value: r }, n), e.push(r), r;
}
function Vt(e) {
	let t = e.blocks?.slice(0) ?? [];
	return e.parent ? [...Vt(e.parent), ...t] : t;
}
function Ht(e, t) {
	if (t.blocks) for (let n = t.blocks.length; n >= 0; n--) {
		let r = t.blocks[n]?.constVars;
		if (r && r.has(e)) return !0;
	}
	return !1;
}
var Ut = new Map([
	["String", String],
	["Date", Date],
	["Blob", Blob],
	["Error", Error]
]);
function Wt(e) {
	return e.map((e) => typeof e == "string" ? e : `${e}`).join("");
}
//#endregion
//#region src/components-core/script-runner/statement-queue.ts
var Gt = class {
	constructor() {
		this.items = [];
	}
	get length() {
		return this.items.length;
	}
	peek() {
		return this.items[0];
	}
	dequeue() {
		return this.items.shift();
	}
	push(e) {
		this.items.push(...e);
	}
	unshift(e) {
		this.items.unshift(...e);
	}
	clearToLabel(e) {
		for (; this.items.length > 0 && this.items[0].label !== e;) this.items.shift();
	}
}, Kt = 1;
function F(e) {
	return [{
		label: Kt++,
		statement: { ...e }
	}];
}
function qt(e) {
	return {
		label: Kt++,
		statement: e.statement,
		execInfo: { ...e.execInfo }
	};
}
function I(e) {
	return e.map(qt);
}
//#endregion
//#region src/components-core/script-runner/process-statement-common.ts
function L(e) {
	if (!e.loops || e.loops.length === 0) throw Error("Missing loop scope");
	return e.loops[e.loops.length - 1];
}
function R(e) {
	if (!(!e.blocks || e.blocks.length === 0)) return e.blocks[e.blocks.length - 1];
}
function z(e) {
	if (!e.tryBlocks || e.tryBlocks.length === 0) throw Error("Missing try scope");
	return e.tryBlocks[e.tryBlocks.length - 1];
}
function B(e, t = 0) {
	e.loops ??= [];
	let n = e.blocks?.length ?? 0, r = e.tryBlocks?.length ?? 0, i = {
		breakLabel: -1,
		continueLabel: -1,
		breakBlockDepth: n,
		continueBlockDepth: n + t,
		tryBlockDepth: r
	};
	return e.loops.push(i), i;
}
function V(e, t = !0) {
	let n = L(e);
	t && e.loops?.pop(), e.blocks && (e.blocks.length = t ? n.breakBlockDepth : n.continueBlockDepth);
}
function H(e) {
	return e.map((e) => ({ statement: e }));
}
function U(e) {
	return {
		statement: e,
		execInfo: { guard: !0 }
	};
}
function W() {
	return {
		statement: {
			type: S,
			nodeId: me()
		},
		execInfo: { removeBlockScope: !0 }
	};
}
function G(e, t, n) {
	let r = U(t), i = I([{ statement: t.body }, r]);
	return e.breakLabel = n ?? -1, e.continueLabel = i[1].label, i;
}
function Jt(e, t) {
	e.tryBlocks ??= [];
	let n = {
		statement: t,
		processingPhase: "try",
		tryLabel: -1
	};
	return e.tryBlocks.push(n), n;
}
function Yt(e, t) {
	let n = U(t.statement);
	e.blocks.push({ vars: {} });
	let r = I([
		...H(t.statement.tryB.stmts),
		W(),
		n
	]);
	return t.tryLabel = r[r.length - 1].label, r;
}
function Xt(e, t) {
	let n = U(t.statement);
	e.blocks.push({ vars: {} });
	let r = I([
		...H(t.statement.catchB.stmts),
		W(),
		n
	]);
	return t.tryLabel = r[r.length - 1].label, r;
}
function K(e, t) {
	let n = U(t.statement);
	e.blocks.push({ vars: {} });
	let r = t.statement.finallyB, i = I([
		...H(r ? r.stmts : []),
		W(),
		n
	]);
	return t.tryLabel = i[i.length - 1].label, i;
}
function q(e) {
	let t = I([U(e.statement)]);
	return e.tryLabel = t[0].label, t;
}
function Zt(e) {
	return e.mainThread ||= {
		childThreads: [],
		blocks: [{ vars: {} }],
		loops: [],
		breakLabelValue: -1
	}, e.mainThread;
}
function Qt(e, t) {
	let n = R(e);
	if (!n) throw Error("Missing block scope");
	t.filter((e) => e.type === i).forEach((t) => {
		let r = t, i = {
			type: x,
			args: r.args,
			statement: r.stmt,
			closureContext: Vt(e),
			_ARROW_EXPR_: !0
		}, a = r.id.name;
		if (n.vars[a]) throw Error(`Variable ${a} is already declared in the current scope.`);
		n.vars[a] = i, n.constVars ??= /* @__PURE__ */ new Set(), n.constVars.add(a);
	});
}
//#endregion
//#region src/components-core/reportEngineError.ts
var $t = [];
function en() {
	$t.length = 0;
}
function J(e, t) {
	typeof e == "string" && (e = Error(e));
	let n = "", r = [];
	if (e instanceof ht) {
		let t = (e?.position ?? 0) - 1;
		if (e.source) {
			for (; t < e.source.length - 1 && e.source[t] === " ";) t++;
			n += `%c${e.message}%c\n\n`, n += `${e.source.substring(0, t)}%c${e.source[t]}%c${e.source.substring(t + 1) ?? ""}\n\n`;
		}
		n += "%cThe error handler associated with the parsed code did not run.%c", r = [
			"color: red",
			"color: inherited",
			"color: red",
			"color: inherited",
			"color: orange",
			"color: inherited"
		];
	} else e instanceof gt ? (n += `%cError while executing code: ${e.message}%c`, e.source && (n += `\n\n${e.source}`), r = ["color: red", "color: inherited"]) : e instanceof O && (n += `A 'throw' statement executed:\n\n%c${e.message}%c\n\n${e.errorObject}`, r = ["color: red", "color: inherited"]);
	throw n && console.error(n, ...r), $t.push({
		error: e,
		helperMessage: n,
		colors: r
	}), t ?? e;
}
//#endregion
//#region src/components-core/appContext/misc-utils.ts
var tn = {
	capitalize: we,
	pluralize: ct,
	defaultTo: Te,
	toHashObject: lt,
	findByField: ut,
	distinct: dt,
	debounce: pt
};
//#endregion
//#region src/components-core/utils/date-utils.ts
function nn(e) {
	return (e ? new Date(e) : /* @__PURE__ */ new Date()).toJSON();
}
function rn(e, t) {
	return t ? w(new Date(e), t) : new Date(e).toLocaleDateString();
}
function an(e, t) {
	return t ? w(new Date(e), t) : new Date(e).toLocaleString();
}
function on(e, t) {
	return t ? w(new Date(e), t) : new Date(e).toLocaleTimeString();
}
function sn(e) {
	return w(new Date(e), "H:m");
}
function cn(e) {
	return new Date(e).toLocaleDateString([], {
		month: "numeric",
		day: "2-digit"
	});
}
function ln(e) {
	return e ? new Date(e) : /* @__PURE__ */ new Date();
}
function un(e, t, n) {
	return e ? qe(e, t, n) : "-";
}
function dn(e) {
	return e ? T(new Date(e)) ? new Date(e).toLocaleTimeString() : Ne(new Date(e)) ? `${je(new Date(e), /* @__PURE__ */ new Date())}` : new Date(e).toLocaleString() : "-";
}
function fn(e) {
	return e ? T(new Date(e)) ? "Today" : Ie(new Date(e)) ? "Yesterday" : new Date(e).toLocaleDateString() : "-";
}
function pn(e) {
	return T(new Date(e));
}
function mn(e) {
	return Ie(new Date(e));
}
function hn(e) {
	return Fe(new Date(e));
}
function gn(e, t = !1) {
	let n = /* @__PURE__ */ new Date(), r = new Date(e), i = n.getTime() - r.getTime();
	if (i < 0) return rn(e);
	let a = Math.floor(i / 1e3), o = Math.floor(a / 60), s = Math.floor(o / 60), c = Math.floor(s / 24), l = Math.floor(c / 7), u = Math.floor(c / 30), d = Math.floor(c / 365), f = {
		second: {
			singular: t ? "s" : "second",
			plural: t ? "s" : "seconds"
		},
		minute: {
			singular: t ? "min" : "minute",
			plural: t ? "min" : "minutes"
		},
		hour: {
			singular: t ? "hr" : "hour",
			plural: t ? "hrs" : "hours"
		},
		day: {
			singular: t ? "d" : "day",
			plural: t ? "d" : "days"
		},
		week: {
			singular: t ? "wk" : "week",
			plural: t ? "wks" : "weeks"
		},
		month: {
			singular: t ? "mo" : "month",
			plural: t ? "mos" : "months"
		},
		year: {
			singular: t ? "y" : "year",
			plural: t ? "yrs" : "years"
		}
	};
	return a < 10 ? "now" : a < 60 ? `${a} ${a === 1 ? f.second.singular : f.second.plural} ago` : o < 60 ? `${o} ${o === 1 ? f.minute.singular : f.minute.plural} ago` : T(r) ? `${s} ${s === 1 ? f.hour.singular : f.hour.plural} ago` : Ie(r) ? "yesterday" : c < 7 ? `${c} ${c === 1 ? f.day.singular : f.day.plural} ago` : l < 4 ? `${l} ${l === 1 ? f.week.singular : f.week.plural} ago` : u < 12 ? `${u} ${u === 1 ? f.month.singular : f.month.plural} ago` : `${d} ${d === 1 ? f.year.singular : f.year.plural} ago`;
}
//#endregion
//#region src/components-core/appContext/date-functions.ts
var _n = {
	isoDateString: nn,
	formatDate: rn,
	formatDateTime: an,
	formatTime: on,
	formatTimeWithoutSeconds: sn,
	formatDateWithoutYear: cn,
	getDate: ln,
	getDateUntilNow: un,
	smartFormatDateTime: dn,
	smartFormatDate: fn,
	isToday: pn,
	isYesterday: mn,
	isTomorrow: hn,
	differenceInMinutes: ke,
	isSameDay: Me,
	isThisYear: Pe,
	formatHumanElapsedTime: gn
};
//#endregion
//#region src/components-core/script-runner/asyncProxy.ts
function vn(e, t, n) {
	let r = Y.get(e);
	return r ? (t.unshift(n), r) : e;
}
var Y = /* @__PURE__ */ new Map();
Y.set(Array.prototype.filter, bn), Y.set(Array.prototype.forEach, xn), Y.set(Array.prototype.map, Sn), Y.set(Array.prototype.every, Cn), Y.set(Array.prototype.findIndex, Tn), Y.set(Array.prototype.find, wn), Y.set(Array.prototype.flatMap, En), Y.set(Array.prototype.some, yn);
async function yn(e, t) {
	let n = await Promise.all(e.map(t));
	return e.some((e, t) => n[t]);
}
async function bn(e, t) {
	let n = await Promise.all(e.map(t));
	return e.filter((e, t) => n[t]);
}
async function xn(e, t) {
	for (let n = 0; n < e.length; n++) await t(e[n], n, e);
}
async function Sn(e, t) {
	let n = [];
	for (let r = 0; r < e.length; r++) n.push(await t(e[r], r, e));
	return n;
}
async function Cn(e, t) {
	let n = await Promise.all(e.map(t));
	return n.every((e, t) => n[t]);
}
async function wn(e, t) {
	let n = await Promise.all(e.map(t));
	return e.find((e, t) => n[t]);
}
async function Tn(e, t) {
	let n = await Promise.all(e.map(t));
	return e.findIndex((e, t) => n[t]);
}
async function En(e, t) {
	let n = await Promise.all(e.map(t));
	return e.flatMap((e, t) => n[t]);
}
//#endregion
//#region src/components-core/script-runner/eval-tree-async.ts
async function X(e, t, n) {
	return Zt(t), n ??= t.mainThread, await On([], e, t, n ?? t.mainThread);
}
async function Dn(e, t, n, ...r) {
	if (e.type !== x) throw Error("executeArrowExpression expects an 'ArrowExpression' object.");
	return await (await Z(On, e))(e.args, t, n ?? t.mainThread, ...r);
}
async function On(e, n, i, o) {
	i.options ||= { defaultToOptionalMemberAccess: !0 };
	let s = On;
	try {
		switch (n.type) {
			case ne: return Hn(s, e, n, i, o);
			case v: return Mt(e, n, o);
			case m: return Nt(e, n, i, o);
			case f: return await kn(s, e, n, i, o);
			case ue: return await An(s, e, n, i, o);
			case t: return await jn(s, e, n, i, o);
			case he: return await Mn(s, e, n, i, o);
			case a: return await Nn(s, e, n, i, o);
			case u: return await Pn(s, e, n, i, o);
			case ce: return await Fn(s, e, n, i, o);
			case le: return await In(s, e, n, i, o);
			case fe: return await Ln(s, e, n, i, o);
			case d:
			case c: return await Rn(s, e, n, i, o);
			case r: return await zn(s, e, n, i, o);
			case x: return Bt(e, n, o);
			case g: throw Error("Cannot use spread expression (...) with the current intermediate value.");
			case se: throw Error("XMLUI does not support the await operator.");
			case p: return await Bn(s, e, n, i, o);
			default: throw Error(`Unknown expression tree node: ${n.type}`);
		}
	} catch (e) {
		throw e;
	}
}
async function kn(e, t, n, r, i) {
	return await e(t, n.obj, r, i), await Q(n.obj, i), Pt(t, n, r, i);
}
async function An(e, t, n, r, i) {
	return await e(t, n.obj, r, i), await Q(n.obj, i), await e(t, n.member, r, i), t.pop(), await Q(n.member, i), Ft(t, n, r, i);
}
function jn(e, t, n, r, i) {
	if (!n.exprs || n.exprs.length === 0) throw Error("Missing expression sequence");
	let a = n.exprs.map(async (n) => {
		let a = await e(t, n, r, i);
		return M(n, { value: a }, i), t.pop(), a;
	}), o = a[a.length - 1];
	return t.push(o), o;
}
async function Mn(e, t, n, r, i) {
	let a = [];
	for (let o of n.items) if (o.type === g) {
		let n = await e(t, o.expr, r, i);
		if (t.pop(), !Array.isArray(n)) throw Error("Spread operator within an array literal expects an array operand.");
		a.push(...n);
	} else a.push(await e(t, o, r, i)), t.pop(), t.push(a);
	return M(n, { value: a }, i), t.push(a), a;
}
async function Nn(e, t, n, r, i) {
	let a = {};
	for (let o of n.props) {
		if (!Array.isArray(o)) {
			let n = await e(t, o.expr, r, i);
			if (t.pop(), Array.isArray(n)) for (let e = 0; e < n.length; e++) a[e] = n[e];
			else if (typeof n == "object") for (let [e, t] of Object.entries(n)) a[e] = t;
			continue;
		}
		let n;
		switch (o[0].type) {
			case v:
				n = o[0].value;
				break;
			case m:
				n = o[0].name;
				break;
			default:
				n = await e(t, o[0], r, i), t.pop();
				break;
		}
		a[n] = await e(t, o[1], r, i), t.pop();
	}
	return M(n, { value: a }, i), t.push(a), a;
}
async function Pn(e, t, n, r, i) {
	return await e(t, n.expr, r, i), t.pop(), await Q(n.expr, i), It(n, t, r, i);
}
async function Fn(e, t, n, r, i) {
	await e(t, n.left, r, i), t.pop();
	let a = await Q(n.left, i);
	return n.op === "&&" && !a || n.op === "||" && a ? (M(n, { value: a }, i), t.push(a), a) : (await e(t, n.right, r, i), t.pop(), await Q(n.right, i), Lt(n, t, r, i));
}
async function In(e, t, n, r, i) {
	await e(t, n.cond, r, i), t.pop();
	let a = await e(t, await Q(n.cond, i) ? n.thenE : n.elseE, r, i);
	return M(n, { value: a }, i), a;
}
async function Ln(e, t, n, r, i) {
	let a = n.leftValue, o = P(a, r, i), s = o && o.type !== "block";
	s && r.onWillUpdate && r.onWillUpdate(o, o.name, "assignment"), await e(t, a, r, i), t.pop(), await Q(a, i), await e(t, n.expr, r, i), t.pop(), await Q(n.expr, i);
	let c = Rt(t, n, r, i);
	return s && r.onDidUpdate && r.onDidUpdate(o, o.name, "assignment"), c;
}
async function Rn(e, t, n, r, i) {
	let a = P(n.expr, r, i), o = a && a.type !== "block";
	o && r.onWillUpdate && r.onWillUpdate(a, a.name, "pre-post"), await e(t, n.expr, r, i), t.pop(), await Q(n.expr, i);
	let s = zt(t, n, r, i);
	return o && r.onDidUpdate && r.onDidUpdate(a, a.name, "pre-post"), s;
}
async function zn(e, t, n, r, i) {
	let a, o = null;
	if (n.obj.type === f) {
		let s = await e(t, n.obj.obj, r, i);
		await Q(n.obj.obj, i), a = Pt(t, n.obj, r, i), n.obj.obj.type === m && s?._SUPPORT_IMPLICIT_CONTEXT && (o = s);
	} else await e(t, n.obj, r, i), a = await Q(n.obj, i);
	t.pop();
	let s = [];
	if (ee(a)) s.push(a.args, r, i, ...n.arguments.map((e) => ({
		...e,
		_EXPRESSION_: !0
	}))), a = await Z(e, a);
	else if (n.obj.type === x) s.push(n.obj.args.map((e) => e.name), r, i, ...n.arguments.map((e) => ({
		...e,
		_EXPRESSION_: !0
	})));
	else {
		for (let t = 0; t < n.arguments.length; t++) {
			let a = n.arguments[t];
			if (a.type === g) {
				await e([], a.expr, r, i);
				let t = await Q(a.expr, i);
				if (!Array.isArray(t)) throw Error("Spread operator within a function invocation expects an array operand.");
				s.push(...t);
			} else if (a.type === x) {
				let t = Z(e, a);
				s.push((...e) => t(a.args, r, i, ...e));
			} else {
				await e([], a, r, i);
				let t = await Q(a, i);
				if (ee(t)) {
					let n = Z(e, t);
					s.push((...e) => n(t.args, r, i, ...e));
				} else s.push(t);
			}
		}
		if (o) if (r.implicitContextGetter) {
			let e = r.implicitContextGetter(o);
			s.unshift(e);
		} else throw Error("Cannot use implicitContextGetter, it is undefined");
	}
	let c = bt(a);
	if (c.banned) throw Error(`Function ${c.func?.name ?? "unknown"} is not allowed to call. ${c?.help ?? ""}`);
	let l = t.length > 0 ? t.pop() : r.localContext;
	a = vn(a, s, l);
	let u = P(n.obj, r, i), d = u && u.type !== "block";
	d && r.onWillUpdate && r.onWillUpdate(u, u.name, "function-call");
	let p = await Vn(r.options?.defaultToOptionalMemberAccess ? a?.call(l, ...s) : a.call(l, ...s));
	return d && r.onDidUpdate && r.onDidUpdate(u, u.name, "function-call"), M(n, { value: p }, i), t.push(p), p;
}
async function Bn(e, t, n, r, i) {
	await e(t, n.callee, r, i);
	let a = await Q(n.callee, i);
	t.pop();
	let o = null;
	for (let [e, t] of Ut) if (a === t) {
		o = t;
		break;
	}
	if (!o) {
		let e = a?.name || "unknown";
		throw Error(`XMLUI does not support the new operator with constructor '${e}'. Only String, Date, and Blob are allowed.`);
	}
	let s = [];
	for (let t = 0; t < n.arguments.length; t++) {
		let a = n.arguments[t];
		if (a.type === g) {
			await e([], a.expr, r, i);
			let t = await Q(a.expr, i);
			if (!Array.isArray(t)) throw Error("Spread operator within a new expression expects an array operand.");
			s.push(...t);
		} else {
			await e([], a, r, i);
			let t = await Q(a, i);
			s.push(t);
		}
	}
	let c = await Vn(new o(...s));
	return M(n, { value: c }, i), t.push(c), c;
}
function Z(e, t) {
	return async (...n) => {
		let r = n[1], i = n[2], a = {
			parent: i,
			childThreads: [],
			blocks: [{ vars: {} }],
			loops: [],
			breakLabelValue: -1,
			closures: t.closureContext
		};
		if (i.childThreads.push(a), t.name) {
			let e = { vars: {} };
			a.blocks ??= [], a.blocks.push(e), e.vars[t.name] = t, e.constVars = new Set([t.name]);
		}
		let o = { vars: {} };
		a.blocks ??= [], a.blocks.push(o);
		let s = n[0], c = !1;
		for (let t = 0; t < s.length; t++) {
			let a = s[t], l;
			switch (a.type) {
				case m:
					l = {
						type: b,
						id: a.name
					};
					break;
				case be:
					l = {
						type: b,
						id: a.id,
						aDestr: a.aDestr,
						oDestr: a.oDestr
					};
					break;
				case g:
					c = !0, l = {
						type: b,
						id: a.expr.name
					};
					break;
				default: throw Error("Unexpected arrow argument specification");
			}
			if (l) if (c) {
				let a = n.slice(t + 3), s = [];
				for (let t of a) t?._EXPRESSION_ ? s.push(await e([], t, r, i)) : s.push(t);
				await $(o, r, i, [l], !1, !0, s);
			} else {
				let a = n[t + 3];
				a?._EXPRESSION_ && (a = await e([], a, r, i)), await $(o, r, i, [l], !1, !0, a);
			}
		}
		let l, u;
		switch (t.statement.type) {
			case S:
				u = [];
				break;
			case h:
				u = [{
					type: C,
					expr: t.statement.expr
				}];
				break;
			case y:
				u = t.statement.stmts;
				break;
			default: throw Error(`Arrow expression with a body of '${t.statement.type}' is not supported yet.`);
		}
		await Un(u, r, a), l = a.returnValue;
		let d = i.childThreads.indexOf(a);
		if (d < 0) throw Error("Cannot find thread to remove.");
		return i.childThreads.splice(d, 1), a.blocks.pop(), l;
	};
}
function Vn(e) {
	let t = /* @__PURE__ */ new Map();
	return n(e);
	async function n(e) {
		if (e == null) return e;
		let r = t.get(e);
		if (r) return r;
		if (jt(e)) {
			let r = await e;
			return t.set(e, r), n(r);
		}
		if (t.set(e, e), Array.isArray(e)) {
			for (let t = 0; t < e.length; t++) {
				let r = await n(e[t]);
				e[t] !== r && e.splice(t, 1, r);
			}
			return e;
		}
		if (De(e)) {
			for (let t of Object.keys(e)) {
				let r = await n(e[t]);
				e[t] !== r && (e[t] = r);
			}
			return e;
		}
		return e;
	}
}
async function Hn(e, t, n, r, i) {
	let a = Array(n.segments.length);
	for (let o = 0; o < n.segments.length; ++o) await e(t, n.segments[o], r, i), t.pop(), a[o] = await Q(n.segments[o], i);
	let o = Wt(a);
	return M(n, { value: o }, i), t.push(o), o;
}
async function Q(e, t) {
	let n = j(e, t), r = await Vn(n?.value);
	return M(e, {
		...n,
		value: r
	}, t), r;
}
//#endregion
//#region src/components-core/script-runner/process-statement-async.ts
async function Un(e, t, n) {
	n ||= Zt(t), Qt(n, e);
	let r = new Gt();
	r.push(I(H(e)));
	let i = {
		processedStatements: 0,
		maxQueueLength: r.length,
		unshiftedItems: 0,
		clearToLabels: 0,
		maxBlocks: 0,
		maxLoops: 0
	}, a = (/* @__PURE__ */ new Date()).getTime();
	for (; r.length > 0 && !t.cancellationToken?.cancelled;) {
		if (t.timeout && (/* @__PURE__ */ new Date()).getTime() - a > t.timeout) throw Error("Script execution timeout");
		let e = r.dequeue();
		n.breakLabelValue = r.length > 0 ? r.peek().label : -1;
		let o;
		try {
			await t?.onStatementStarted?.(t, e.statement), o = await Wn(e.statement, e?.execInfo ?? {}, t, n);
		} catch (e) {
			if (n.tryBlocks && n.tryBlocks.length > 0) {
				let t = n.tryBlocks[n.tryBlocks.length - 1];
				t.errorToThrow = e, t.errorSource = t.processingPhase, t.processingPhase = "error", o = { clearToLabel: t.tryLabel };
			} else e instanceof O ? J(e) : J(new gt(e), e);
		}
		o && (o.toUnshift && (r.unshift(o.toUnshift), i.unshiftedItems += o.toUnshift.length), o.clearToLabel !== void 0 && (r.clearToLabel(o.clearToLabel), i.clearToLabels++)), await t?.onStatementCompleted?.(t, e.statement), r.length > i.maxQueueLength && (i.maxQueueLength = r.length), n.blocks && n.blocks.length > i.maxBlocks && (i.maxBlocks = n.blocks.length), n.loops && n.loops.length > i.maxLoops && (i.maxLoops = n.loops.length), i.processedStatements++;
	}
	return i;
}
async function Wn(t, r, a, c) {
	let u = [], d;
	switch (t.type) {
		case _e: throw Error("XMLUI does not support async function declarations.");
		case i: break;
		case l:
			if (c !== a.mainThread) throw Error("'var' declarations are not allowed within functions");
			break;
		case S: break;
		case y:
			if (t.stmts.length === 0) break;
			c.blocks ??= [], c.blocks.push({ vars: {} }), Qt(c, t.stmts), u = I([...H(t.stmts), W()]);
			break;
		case h:
			let f = await X(t.expr, a, c);
			c.blocks && c.blocks.length !== 0 && (c.blocks[c.blocks.length - 1].returnValue = f);
			break;
		case _:
			let p = await Dn(t.expr, a, c, ...a.eventArgs ?? []);
			c.blocks && c.blocks.length !== 0 && (c.blocks[c.blocks.length - 1].returnValue = p);
			break;
		case e: {
			let e = R(c);
			if (!e) throw Error("Missing block scope");
			await $(e, a, c, t.decls);
			break;
		}
		case ae: {
			let e = R(c);
			if (!e) throw Error("Missing block scope");
			await $(e, a, c, t.decls, !0);
			break;
		}
		case de:
			await X(t.cond, a, c) ? u = F(t.thenB) : t.elseB && (u = F(t.elseB));
			break;
		case C:
			if (R(c) === void 0) throw Error("Return requires a block scope");
			if (c.returnValue = t.expr ? await X(t.expr, a, c) : void 0, (c.tryBlocks ?? []).length > 0) {
				for (let e = 0; e < c.tryBlocks.length; e++) c.tryBlocks[e].exitType = "return";
				let e = z(c);
				e.processingPhase !== "postFinally" && c.blocks.pop(), d = e.tryLabel;
			} else d = -1;
			break;
		case ie: {
			let e = r.guard ? L(c) : B(c);
			await X(t.cond, a, c) ? u = G(e, t, c.breakLabelValue) : V(c);
			break;
		}
		case oe:
			if (!r.guard) {
				u = G(B(c), t, c.breakLabelValue);
				break;
			}
			await X(t.cond, a, c) ? u = G(L(c), t, c.breakLabelValue) : V(c);
			break;
		case ve: {
			if (!c.loops || c.loops.length === 0) throw Error("Missing loop scope");
			let e;
			for (; c.loops.length > 0 && (e = L(c), e.isSwitch);) c.loops.pop();
			if (!e) throw Error("Missing loop scope");
			if (e.tryBlockDepth >= 0 && e.tryBlockDepth < (c.tryBlocks ?? []).length) {
				for (let t = e.tryBlockDepth; t < c.tryBlocks.length; t++) c.tryBlocks[e.tryBlockDepth].exitType = "continue";
				d = z(c).tryLabel;
			} else d = e.continueLabel, V(c, !1);
			break;
		}
		case pe: {
			let e = L(c);
			if (e === void 0) throw Error("Missing loop scope");
			if (e.isSwitch) {
				d = e.breakLabel;
				break;
			}
			if (e.tryBlockDepth >= 0 && e.tryBlockDepth < (c.tryBlocks ?? []).length) {
				for (let t = e.tryBlockDepth; t < c.tryBlocks.length; t++) c.tryBlocks[e.tryBlockDepth].exitType = "break";
				d = z(c).tryLabel;
			} else d = e.breakLabel, V(c);
			break;
		}
		case te:
			if (!r.guard) {
				B(c, 1), c.blocks ??= [], c.blocks.push({ vars: {} });
				let e = U(t);
				u = t.init ? I([{ statement: t.init }, e]) : I([e]);
			} else if (!t.cond || await X(t.cond, a, c)) {
				let e = L(c);
				if (t.upd) {
					let e = { statement: {
						type: h,
						nodeId: me(),
						expr: t.upd
					} };
					u = I([
						{ statement: t.body },
						e,
						{
							statement: t,
							execInfo: r
						}
					]);
				} else u = I([{ statement: t.body }, {
					statement: t,
					execInfo: r
				}]);
				e.breakLabel = c.breakLabelValue ?? -1, e.continueLabel = u[1].label;
			} else V(c);
			break;
		case n:
			if (r.guard) {
				if (r.keyIndex === void 0 || r.keys === void 0) throw Error("Keys information expected in for..in loop");
				if (r.keyIndex < r.keys.length) {
					let e = r.keys[r.keyIndex++];
					switch (t.varB) {
						case "none":
							await X({
								type: fe,
								leftValue: {
									type: m,
									name: t.id.name
								},
								op: "=",
								expr: {
									type: v,
									value: e
								}
							}, a, c);
							break;
						case "const":
						case "let":
							{
								let n = R(c);
								if (!n) throw Error("Missing block scope");
								n.vars[t.id.name] = e, t.varB === "const" && (n.constVars ??= /* @__PURE__ */ new Set(), n.constVars.add(t.id.name));
							}
							break;
					}
					let n = L(c);
					u = I([{ statement: t.body }, {
						statement: t,
						execInfo: r
					}]), n.breakLabel = c.breakLabelValue ?? -1, n.continueLabel = u[1].label;
				} else V(c);
			} else {
				let e = await X(t.expr, a, c);
				if (e == null) break;
				B(c, 1), c.blocks ??= [], c.blocks.push({ vars: {} }), u = I([{
					statement: t,
					execInfo: {
						guard: !0,
						keys: Object.keys(e),
						keyIndex: 0
					}
				}]);
			}
			break;
		case ye:
			if (r.guard) {
				if (r.iterator === void 0) throw Error("Iterator expected in for..of loop");
				let e = r.iterator.next();
				if (e.done) {
					V(c);
					break;
				}
				let n = e.value;
				switch (t.varB) {
					case "none":
						await X({
							type: fe,
							leftValue: {
								type: m,
								name: t.id.name
							},
							op: "=",
							expr: {
								type: v,
								value: n
							}
						}, a, c);
						break;
					case "const":
					case "let":
						{
							let e = R(c);
							if (!e) throw Error("Missing block scope");
							e.vars[t.id.name] = n, t.varB === "const" && (e.constVars ??= /* @__PURE__ */ new Set(), e.constVars.add(t.id.name));
						}
						break;
				}
				let i = L(c);
				u = I([{ statement: t.body }, {
					statement: t,
					execInfo: r
				}]), i.breakLabel = c.breakLabelValue ?? -1, i.continueLabel = u[1].label;
			} else {
				let e = await X(t.expr, a, c);
				if (e == null || typeof e[Symbol.iterator] != "function") throw Error("Object in for..of is not iterable");
				B(c, 1), c.blocks ??= [], c.blocks.push({ vars: {} }), u = I([{
					statement: t,
					execInfo: {
						guard: !0,
						iterator: e[Symbol.iterator]()
					}
				}]);
			}
			break;
		case re: throw new O(await X(t.expr, a, c));
		case o: {
			if (!r.guard) {
				u = Yt(c, Jt(c, t));
				break;
			}
			let e = z(c);
			switch (e.processingPhase) {
				case "error":
					switch (e.errorSource) {
						case "try":
							if (c.blocks.pop(), t.catchB) {
								if (e.statement.catchV) {
									let t = R(c);
									t.vars[e.statement.catchV.name] = e.errorToThrow instanceof O ? e.errorToThrow.errorObject : e.errorToThrow;
								}
								delete e.errorToThrow, e.processingPhase = "catch", u = Xt(c, e);
							} else e.statement.finallyB && (e.processingPhase = "finally", u = K(c, e));
							break;
						case "catch":
							c.blocks.pop(), e.processingPhase = "finally", u = K(c, e);
							break;
						case "finally":
							c.blocks.pop(), e.processingPhase = "postFinally", u = q(e);
							break;
					}
					break;
				case "try":
					e.processingPhase = "finally", u = t.finallyB ? K(c, e) : q(e);
					break;
				case "catch":
					e.processingPhase = "finally", u = t.finallyB ? K(c, e) : q(e);
					break;
				case "finally":
					e.processingPhase = "postFinally", u = q(e);
					break;
				case "postFinally":
					let n = c.tryBlocks.pop();
					switch (n.exitType) {
						case "break": {
							let e = L(c);
							if (e === void 0) throw Error("Missing loop scope");
							V(c), d = e.breakLabel;
							break;
						}
						case "continue": {
							let e = L(c);
							if (e === void 0) throw Error("Missing loop scope");
							d = e.continueLabel, V(c, !1);
							break;
						}
						case "return":
							c.tryBlocks && c.tryBlocks.length > 0 ? (c.blocks && c.blocks.length > 1 && c.blocks.pop(), d = c.tryBlocks[c.tryBlocks.length - 1].tryLabel) : d = -1;
							break;
					}
					if (n.errorToThrow) throw n.errorToThrow;
					break;
			}
			break;
		}
		case s:
			if (r.guard) V(c);
			else {
				let e = B(c);
				e.isSwitch = !0, c.blocks.push({ vars: {} });
				let n = await X(t.expr, a, c), r = -1;
				for (let e = 0; e < t.cases.length; e++) {
					let i = t.cases[e];
					if (i.caseE === void 0) {
						r = e;
						break;
					}
					if (await X(i.caseE, a, c) === n) {
						r = e;
						break;
					}
				}
				let i = [];
				if (r >= 0) for (let e = r; e < t.cases.length; e++) i.push(...t.cases[e].stmts);
				u = I([...H(i), U(t)]), e.breakLabel = u[u.length - 1].label;
			}
			break;
	}
	return r.removeBlockScope && c.blocks && c.blocks.length > 0 && c.blocks.pop(), {
		toUnshift: u,
		clearToLabel: d
	};
}
async function $(e, t, n, r, i = !1, a = !1, o = void 0) {
	for (let c = 0; c < r.length; c++) {
		let l, u = r[c];
		a ? l = o : u.expr && (l = await X(u.expr, t, n)), s(e, u, l, i);
	}
	function s(e, t, n, r) {
		if (t.id) c(e, t.id, n, r);
		else if (t.aDestr) l(e, t.aDestr, n, r);
		else if (t.oDestr) u(e, t.oDestr, n, r);
		else throw Error("Unknown declaration specifier");
	}
	function c(e, t, n, r) {
		if (e.vars[t]) throw Error(`Variable ${t} is already declared in the current scope.`);
		e.vars[t] = n, r && (e.constVars ??= /* @__PURE__ */ new Set(), e.constVars.add(t));
	}
	function l(e, t, n, r) {
		for (let i = 0; i < t.length; i++) {
			let a = t[i], o = n?.[i];
			a.id ? c(e, a.id, o, r) : a.aDestr ? l(e, a.aDestr, o, r) : a.oDestr && u(e, a.oDestr, o, r);
		}
	}
	function u(e, t, n, r) {
		for (let i = 0; i < t.length; i++) {
			let a = t[i], o = n?.[a.id];
			a.aDestr ? l(e, a.aDestr, o, r) : a.oDestr ? u(e, a.oDestr, o, r) : c(e, a.alias ?? a.id, o, r);
		}
	}
}
//#endregion
//#region src/components-core/utils/statementUtils.ts
function Gn(e) {
	let t = new ge(e), n = null;
	try {
		n = t.parseStatements();
	} catch (n) {
		if (t.errors.length > 0) {
			let n = t.errors[0];
			J(new ht(`${n.code}(${n.line}, ${n.column}): ${t.errors[0].text}`, e, n.position));
		} else throw n;
	}
	if (!t.isEof) {
		let n = t.getTail();
		J(new ht("Invalid tail found", e, e.length - n.length + 1));
	}
	return n;
}
function Kn(e, t) {
	let n = e?.length ?? 0;
	if (n === 0) return [{
		type: _,
		expr: {
			type: x,
			args: [],
			statement: { type: S }
		}
	}];
	if (n === 1) {
		let n = e[0];
		if (n.type === h) return t && (n.expr.type === m || i(n.expr)) ? [a(n.expr)] : n.expr.type === x ? [{
			type: _,
			expr: n.expr
		}] : [{
			type: _,
			expr: {
				type: x,
				args: [],
				statement: e[0]
			}
		}];
		if (n.type === C) return [{
			type: _,
			expr: {
				type: x,
				args: [],
				statement: {
					type: y,
					stmts: [n]
				}
			}
		}];
		if (n.type === y) return n.stmts[0].type === h && n.stmts[0].expr.type === x ? [{
			type: _,
			expr: n.stmts[0].expr
		}] : [{
			type: _,
			expr: {
				type: x,
				args: [],
				statement: e[0]
			}
		}];
	}
	if (n > 1) return [{
		type: _,
		expr: {
			type: x,
			args: [],
			statement: {
				type: y,
				stmts: e
			}
		}
	}];
	return e;
	function i(e) {
		return (e.type === f || e.type === ue && e.member.type === v) && (i(e.obj) || e.obj.type === m);
	}
	function a(e) {
		let n = t.eventArgs ? t.eventArgs.map((e, t) => ({
			type: m,
			name: `__arg@@#__${t}__`
		})) : [];
		return t.eventArgs && t.eventArgs.forEach((e, n) => {
			t.localContext[`__arg@@#__${n}__`] = e;
		}), {
			type: _,
			expr: {
				type: x,
				args: n,
				statement: {
					type: h,
					expr: {
						type: r,
						obj: e,
						arguments: [...n]
					}
				}
			}
		};
	}
}
async function qn(e, t, n) {
	return await Un(Kn(Gn(e)), t, n);
}
//#endregion
export { Ue as $, Bt as A, j as B, Yt as C, I as D, Gt as E, Mt as F, bt as G, P as H, Pt as I, gt as J, mt as K, zt as L, Lt as M, Ft as N, F as O, Nt as P, He as Q, Wt as R, G as S, H as T, jt as U, N as V, M as W, vt as X, O as Y, ft as Z, L as _, _n as a, at, K as b, J as c, Le as ct, B as d, Ve as dt, Xe as et, Jt as f, We as ft, R as g, Qt as h, Un as i, Qe as it, Rt as j, Ut as k, en as l, it as lt, U as m, Ge as mt, Kn as n, ze as nt, ln as o, Ze as ot, Zt as p, et as pt, _t as q, qn as r, st as rt, tn as s, $e as st, Gn as t, ot as tt, W as u, Be as ut, z as v, V as w, q as x, Xt as y, It as z };

//# sourceMappingURL=statementUtils-yh6R4BAa.js.map