import { $ as e, A as t, At as n, C as r, D as i, E as a, Et as o, F as s, Ft as c, G as l, Gt as u, I as d, J as f, K as p, Kt as m, L as h, Mt as g, N as _, Nt as v, O as ee, Ot as te, P as ne, Pt as re, Q as ie, R as ae, Rt as oe, S as se, St as ce, T as le, Tt as ue, U as de, Ut as fe, W as y, X as b, Xt as pe, Y as me, Z as he, _ as ge, _t as _e, a as x, at as S, b as ve, bt as ye, c as C, cn as be, ct as xe, d as w, dt as T, et as Se, f as E, ft as Ce, g as D, gn as O, gt as k, h as A, hn as we, ht as j, i as Te, it as M, j as Ee, jt as De, k as Oe, kt as ke, l as N, lt as Ae, m as je, mn as Me, mt as Ne, n as P, nt as Pe, o as F, ot as Fe, p as I, q as Ie, r as Le, rn as Re, rt as ze, s as L, st as Be, t as Ve, tt as He, u as Ue, un as R, ut as z, v as B, w as We, wt as V, x as Ge, xt as Ke, y as H } from "./process-statement-common-C3Zo_IH-.js";
import { capitalize as qe, defaultTo as Je, isPlainObject as Ye } from "lodash-es";
import { differenceInMinutes as Xe, format as U, formatRelative as Ze, isSameDay as Qe, isThisWeek as $e, isThisYear as et, isToday as W, isTomorrow as tt, isYesterday as G } from "date-fns";
//#region src/components-core/appContext/misc-utils.ts
var nt = {
	capitalize: qe,
	pluralize: Re,
	defaultTo: Je,
	toHashObject: be,
	findByField: m,
	distinct: u,
	debounce: fe
};
//#endregion
//#region src/components-core/utils/date-utils.ts
function rt(e) {
	return (e ? new Date(e) : /* @__PURE__ */ new Date()).toJSON();
}
function it(e, t) {
	return t ? U(new Date(e), t) : new Date(e).toLocaleDateString();
}
function at(e, t) {
	return t ? U(new Date(e), t) : new Date(e).toLocaleString();
}
function ot(e, t) {
	return t ? U(new Date(e), t) : new Date(e).toLocaleTimeString();
}
function st(e) {
	return U(new Date(e), "H:m");
}
function ct(e) {
	return new Date(e).toLocaleDateString([], {
		month: "numeric",
		day: "2-digit"
	});
}
function lt(e) {
	return e ? new Date(e) : /* @__PURE__ */ new Date();
}
function ut(e, t, n) {
	return e ? pe(e, t, n) : "-";
}
function dt(e) {
	return e ? W(new Date(e)) ? new Date(e).toLocaleTimeString() : $e(new Date(e)) ? `${Ze(new Date(e), /* @__PURE__ */ new Date())}` : new Date(e).toLocaleString() : "-";
}
function ft(e) {
	return e ? W(new Date(e)) ? "Today" : G(new Date(e)) ? "Yesterday" : new Date(e).toLocaleDateString() : "-";
}
function pt(e) {
	return W(new Date(e));
}
function mt(e) {
	return G(new Date(e));
}
function ht(e) {
	return tt(new Date(e));
}
function gt(e, t = !1) {
	let n = /* @__PURE__ */ new Date(), r = new Date(e), i = n.getTime() - r.getTime();
	if (i < 0) return it(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` : W(r) ? `${s} ${s === 1 ? f.hour.singular : f.hour.plural} ago` : G(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 _t = {
	isoDateString: rt,
	formatDate: it,
	formatDateTime: at,
	formatTime: ot,
	formatTimeWithoutSeconds: st,
	formatDateWithoutYear: ct,
	getDate: lt,
	getDateUntilNow: ut,
	smartFormatDateTime: dt,
	smartFormatDate: ft,
	isToday: pt,
	isYesterday: mt,
	isTomorrow: ht,
	differenceInMinutes: Xe,
	isSameDay: Qe,
	isThisYear: et,
	formatHumanElapsedTime: gt
};
//#endregion
//#region src/components-core/script-runner/asyncProxy.ts
function vt(e, t, n) {
	let r = K.get(e);
	return r ? (t.unshift(n), r) : e;
}
var K = /* @__PURE__ */ new Map();
K.set(Array.prototype.filter, bt), K.set(Array.prototype.forEach, xt), K.set(Array.prototype.map, St), K.set(Array.prototype.every, Ct), K.set(Array.prototype.findIndex, Tt), K.set(Array.prototype.find, wt), K.set(Array.prototype.flatMap, Et), K.set(Array.prototype.some, yt);
async function yt(e, t) {
	let n = await Promise.all(e.map(t));
	return e.some((e, t) => n[t]);
}
async function bt(e, t) {
	let n = await Promise.all(e.map(t));
	return e.filter((e, t) => n[t]);
}
async function xt(e, t) {
	for (let n = 0; n < e.length; n++) await t(e[n], n, e);
}
async function St(e, t) {
	let n = [];
	for (let r = 0; r < e.length; r++) n.push(await t(e[r], r, e));
	return n;
}
async function Ct(e, t) {
	let n = await Promise.all(e.map(t));
	return n.every((e, t) => n[t]);
}
async function wt(e, t) {
	let n = await Promise.all(e.map(t));
	return e.find((e, t) => n[t]);
}
async function Tt(e, t) {
	let n = await Promise.all(e.map(t));
	return e.findIndex((e, t) => n[t]);
}
async function Et(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 q(e, t, n) {
	return Te(t), n ??= t.mainThread, await J([], e, t, n ?? t.mainThread);
}
async function Dt(e, t, n, ...r) {
	if (e.type !== y) throw Error("executeArrowExpression expects an 'ArrowExpression' object.");
	return await (await Y(J, e))(e.args, t, n ?? t.mainThread, ...r);
}
async function J(t, n, r, i) {
	r.options ||= { defaultToOptionalMemberAccess: !0 };
	let s = J;
	try {
		switch (n.type) {
			case ke: return Bt(s, t, n, r, i);
			case j: return a(t, n, i);
			case T: return le(t, n, r, i);
			case k: return await Ot(s, t, n, r, i);
			case ie: return await kt(s, t, n, r, i);
			case ue: return await At(s, t, n, r, i);
			case de: return await jt(s, t, n, r, i);
			case ye: return await Mt(s, t, n, r, i);
			case g: return await Nt(s, t, n, r, i);
			case me: return await Pt(s, t, n, r, i);
			case e: return await Ft(s, t, n, r, i);
			case p: return await It(s, t, n, r, i);
			case ce:
			case Ke: return await Lt(s, t, n, r, i);
			case z: return await Rt(s, t, n, r, i);
			case y: return Ge(t, n, i);
			case o: throw Error("Cannot use spread expression (...) with the current intermediate value.");
			case f: throw Error("XMLUI does not support the await operator.");
			case _e: return await zt(s, t, n, r, i);
			default: throw Error(`Unknown expression tree node: ${n.type}`);
		}
	} catch (e) {
		throw e;
	}
}
async function Ot(e, t, n, r, a) {
	return await e(t, n.obj, r, a), await Z(n.obj, a), i(t, n, r, a);
}
async function kt(e, t, n, r, i) {
	return await e(t, n.obj, r, i), await Z(n.obj, i), await e(t, n.member, r, i), t.pop(), await Z(n.member, i), We(t, n, r, i);
}
function At(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 s(n, { value: a }, i), t.pop(), a;
	}), o = a[a.length - 1];
	return t.push(o), o;
}
async function jt(e, t, n, r, i) {
	let a = [];
	for (let s of n.items) if (s.type === o) {
		let n = await e(t, s.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, s, r, i)), t.pop(), t.push(a);
	return s(n, { value: a }, i), t.push(a), a;
}
async function Mt(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 j:
				n = o[0].value;
				break;
			case T:
				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 s(n, { value: a }, i), t.push(a), a;
}
async function Nt(e, n, r, i, a) {
	return await e(n, r.expr, i, a), n.pop(), await Z(r.expr, a), t(r, n, i, a);
}
async function Pt(e, t, n, i, a) {
	await e(t, n.left, i, a), t.pop();
	let o = await Z(n.left, a);
	return n.op === "&&" && !o || n.op === "||" && o ? (s(n, { value: o }, a), t.push(o), o) : (await e(t, n.right, i, a), t.pop(), await Z(n.right, a), r(n, t, i, a));
}
async function Ft(e, t, n, r, i) {
	await e(t, n.cond, r, i), t.pop();
	let a = await e(t, await Z(n.cond, i) ? n.thenE : n.elseE, r, i);
	return s(n, { value: a }, i), a;
}
async function It(e, t, n, r, i) {
	let a = n.leftValue, o = _(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 Z(a, i), await e(t, n.expr, r, i), t.pop(), await Z(n.expr, i);
	let c = se(t, n, r, i);
	return s && r.onDidUpdate && r.onDidUpdate(o, o.name, "assignment"), c;
}
async function Lt(e, t, n, r, i) {
	let a = _(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 Z(n.expr, i);
	let s = ee(t, n, r, i);
	return o && r.onDidUpdate && r.onDidUpdate(a, a.name, "pre-post"), s;
}
async function Rt(e, t, n, r, a) {
	let c, l = null;
	if (n.obj.type === k) {
		let o = await e(t, n.obj.obj, r, a);
		await Z(n.obj.obj, a), c = i(t, n.obj, r, a), n.obj.obj.type === T && o?._SUPPORT_IMPLICIT_CONTEXT && (l = o);
	} else await e(t, n.obj, r, a), c = await Z(n.obj, a);
	t.pop();
	let u = [];
	if (oe(c)) u.push(c.args, r, a, ...n.arguments.map((e) => ({
		...e,
		_EXPRESSION_: !0
	}))), c = await Y(e, c);
	else if (n.obj.type === y) u.push(n.obj.args.map((e) => e.name), r, a, ...n.arguments.map((e) => ({
		...e,
		_EXPRESSION_: !0
	})));
	else {
		for (let t = 0; t < n.arguments.length; t++) {
			let i = n.arguments[t];
			if (i.type === o) {
				await e([], i.expr, r, a);
				let t = await Z(i.expr, a);
				if (!Array.isArray(t)) throw Error("Spread operator within a function invocation expects an array operand.");
				u.push(...t);
			} else if (i.type === y) {
				let t = Y(e, i);
				u.push((...e) => t(i.args, r, a, ...e));
			} else {
				await e([], i, r, a);
				let t = await Z(i, a);
				if (oe(t)) {
					let n = Y(e, t);
					u.push((...e) => n(t.args, r, a, ...e));
				} else u.push(t);
			}
		}
		if (l) if (r.implicitContextGetter) {
			let e = r.implicitContextGetter(l);
			u.unshift(e);
		} else throw Error("Cannot use implicitContextGetter, it is undefined");
	}
	let f = d(c);
	if (f.banned) throw Error(`Function ${f.func?.name ?? "unknown"} is not allowed to call. ${f?.help ?? ""}`);
	let p = t.length > 0 ? t.pop() : r.localContext;
	c = vt(c, u, p);
	let m = _(n.obj, r, a), h = m && m.type !== "block";
	h && r.onWillUpdate && r.onWillUpdate(m, m.name, "function-call");
	let g = await X(r.options?.defaultToOptionalMemberAccess ? c?.call(p, ...u) : c.call(p, ...u));
	return h && r.onDidUpdate && r.onDidUpdate(m, m.name, "function-call"), s(n, { value: g }, a), t.push(g), g;
}
async function zt(e, t, n, r, i) {
	await e(t, n.callee, r, i);
	let a = await Z(n.callee, i);
	t.pop();
	let c = null;
	for (let [e, t] of ve) if (a === t) {
		c = t;
		break;
	}
	if (!c) {
		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 l = [];
	for (let t = 0; t < n.arguments.length; t++) {
		let a = n.arguments[t];
		if (a.type === o) {
			await e([], a.expr, r, i);
			let t = await Z(a.expr, i);
			if (!Array.isArray(t)) throw Error("Spread operator within a new expression expects an array operand.");
			l.push(...t);
		} else {
			await e([], a, r, i);
			let t = await Z(a, i);
			l.push(t);
		}
	}
	let u = await X(new c(...l));
	return s(n, { value: u }, i), t.push(u), u;
}
function Y(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 s = { vars: {} };
		a.blocks ??= [], a.blocks.push(s);
		let c = n[0], l = !1;
		for (let t = 0; t < c.length; t++) {
			let a = c[t], u;
			switch (a.type) {
				case T:
					u = {
						type: v,
						id: a.name
					};
					break;
				case Pe:
					u = {
						type: v,
						id: a.id,
						aDestr: a.aDestr,
						oDestr: a.oDestr
					};
					break;
				case o:
					l = !0, u = {
						type: v,
						id: a.expr.name
					};
					break;
				default: throw Error("Unexpected arrow argument specification");
			}
			if (u) if (l) {
				let a = n.slice(t + 3), o = [];
				for (let t of a) t?._EXPRESSION_ ? o.push(await e([], t, r, i)) : o.push(t);
				await $(s, r, i, [u], !1, !0, o);
			} else {
				let a = n[t + 3];
				a?._EXPRESSION_ && (a = await e([], a, r, i)), await $(s, r, i, [u], !1, !0, a);
			}
		}
		let u, d;
		switch (t.statement.type) {
			case M:
				d = [];
				break;
			case S:
				d = [{
					type: V,
					expr: t.statement.expr
				}];
				break;
			case b:
				d = t.statement.stmts;
				break;
			default: throw Error(`Arrow expression with a body of '${t.statement.type}' is not supported yet.`);
		}
		await Q(d, r, a), u = a.returnValue;
		let f = i.childThreads.indexOf(a);
		if (f < 0) throw Error("Cannot find thread to remove.");
		return i.childThreads.splice(f, 1), a.blocks.pop(), u;
	};
}
function X(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 (ne(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 (Ye(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 Bt(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 Z(n.segments[o], i);
	let o = Oe(a);
	return s(n, { value: o }, i), t.push(o), o;
}
async function Z(e, t) {
	let n = Ee(e, t), r = await X(n?.value);
	return s(e, {
		...n,
		value: r
	}, t), r;
}
//#endregion
//#region src/components-core/script-runner/process-statement-async.ts
async function Q(e, t, n) {
	n ||= Te(t), F(n, e);
	let r = new ge();
	r.push(B(D(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 Vt(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 ? R(e) : R(new we(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 Vt(e, t, r, i) {
	let a = [], o;
	switch (e.type) {
		case Ie: throw Error("XMLUI does not support async function declarations.");
		case Ae: break;
		case re:
			if (i !== r.mainThread) throw Error("'var' declarations are not allowed within functions");
			break;
		case M: break;
		case b:
			if (e.stmts.length === 0) break;
			i.blocks ??= [], i.blocks.push({ vars: {} }), F(i, e.stmts), a = B([...D(e.stmts), Ve()]);
			break;
		case S:
			let s = await q(e.expr, r, i);
			i.blocks && i.blocks.length !== 0 && (i.blocks[i.blocks.length - 1].returnValue = s);
			break;
		case l:
			let u = await Dt(e.expr, r, i, ...r.eventArgs ?? []);
			i.blocks && i.blocks.length !== 0 && (i.blocks[i.blocks.length - 1].returnValue = u);
			break;
		case Ne: {
			let t = L(i);
			if (!t) throw Error("Missing block scope");
			await $(t, r, i, e.decls);
			break;
		}
		case Se: {
			let t = L(i);
			if (!t) throw Error("Missing block scope");
			await $(t, r, i, e.decls, !0);
			break;
		}
		case Ce:
			await q(e.cond, r, i) ? a = H(e.thenB) : e.elseB && (a = H(e.elseB));
			break;
		case V:
			if (L(i) === void 0) throw Error("Return requires a block scope");
			if (i.returnValue = e.expr ? await q(e.expr, r, i) : void 0, (i.tryBlocks ?? []).length > 0) {
				for (let e = 0; e < i.tryBlocks.length; e++) i.tryBlocks[e].exitType = "return";
				let e = N(i);
				e.processingPhase !== "postFinally" && i.blocks.pop(), o = e.tryLabel;
			} else o = -1;
			break;
		case c: {
			let n = t.guard ? C(i) : P(i);
			await q(e.cond, r, i) ? a = I(n, e, i.breakLabelValue) : A(i);
			break;
		}
		case ze:
			if (!t.guard) {
				a = I(P(i), e, i.breakLabelValue);
				break;
			}
			await q(e.cond, r, i) ? a = I(C(i), e, i.breakLabelValue) : A(i);
			break;
		case He: {
			if (!i.loops || i.loops.length === 0) throw Error("Missing loop scope");
			let e;
			for (; i.loops.length > 0 && (e = C(i), e.isSwitch);) i.loops.pop();
			if (!e) throw Error("Missing loop scope");
			if (e.tryBlockDepth >= 0 && e.tryBlockDepth < (i.tryBlocks ?? []).length) {
				for (let t = e.tryBlockDepth; t < i.tryBlocks.length; t++) i.tryBlocks[e.tryBlockDepth].exitType = "continue";
				o = N(i).tryLabel;
			} else o = e.continueLabel, A(i, !1);
			break;
		}
		case he: {
			let e = C(i);
			if (e === void 0) throw Error("Missing loop scope");
			if (e.isSwitch) {
				o = e.breakLabel;
				break;
			}
			if (e.tryBlockDepth >= 0 && e.tryBlockDepth < (i.tryBlocks ?? []).length) {
				for (let t = e.tryBlockDepth; t < i.tryBlocks.length; t++) i.tryBlocks[e.tryBlockDepth].exitType = "break";
				o = N(i).tryLabel;
			} else o = e.breakLabel, A(i);
			break;
		}
		case xe:
			if (!t.guard) {
				P(i, 1), i.blocks ??= [], i.blocks.push({ vars: {} });
				let t = x(e);
				a = e.init ? B([{ statement: e.init }, t]) : B([t]);
			} else if (!e.cond || await q(e.cond, r, i)) {
				let n = C(i);
				if (e.upd) {
					let n = { statement: {
						type: S,
						nodeId: ae(),
						expr: e.upd
					} };
					a = B([
						{ statement: e.body },
						n,
						{
							statement: e,
							execInfo: t
						}
					]);
				} else a = B([{ statement: e.body }, {
					statement: e,
					execInfo: t
				}]);
				n.breakLabel = i.breakLabelValue ?? -1, n.continueLabel = a[1].label;
			} else A(i);
			break;
		case Fe:
			if (t.guard) {
				if (t.keyIndex === void 0 || t.keys === void 0) throw Error("Keys information expected in for..in loop");
				if (t.keyIndex < t.keys.length) {
					let n = t.keys[t.keyIndex++];
					switch (e.varB) {
						case "none":
							await q({
								type: p,
								leftValue: {
									type: T,
									name: e.id.name
								},
								op: "=",
								expr: {
									type: j,
									value: n
								}
							}, r, i);
							break;
						case "const":
						case "let":
							{
								let t = L(i);
								if (!t) throw Error("Missing block scope");
								t.vars[e.id.name] = n, e.varB === "const" && (t.constVars ??= /* @__PURE__ */ new Set(), t.constVars.add(e.id.name));
							}
							break;
					}
					let o = C(i);
					a = B([{ statement: e.body }, {
						statement: e,
						execInfo: t
					}]), o.breakLabel = i.breakLabelValue ?? -1, o.continueLabel = a[1].label;
				} else A(i);
			} else {
				let t = await q(e.expr, r, i);
				if (t == null) break;
				P(i, 1), i.blocks ??= [], i.blocks.push({ vars: {} }), a = B([{
					statement: e,
					execInfo: {
						guard: !0,
						keys: Object.keys(t),
						keyIndex: 0
					}
				}]);
			}
			break;
		case Be:
			if (t.guard) {
				if (t.iterator === void 0) throw Error("Iterator expected in for..of loop");
				let n = t.iterator.next();
				if (n.done) {
					A(i);
					break;
				}
				let o = n.value;
				switch (e.varB) {
					case "none":
						await q({
							type: p,
							leftValue: {
								type: T,
								name: e.id.name
							},
							op: "=",
							expr: {
								type: j,
								value: o
							}
						}, r, i);
						break;
					case "const":
					case "let":
						{
							let t = L(i);
							if (!t) throw Error("Missing block scope");
							t.vars[e.id.name] = o, e.varB === "const" && (t.constVars ??= /* @__PURE__ */ new Set(), t.constVars.add(e.id.name));
						}
						break;
				}
				let s = C(i);
				a = B([{ statement: e.body }, {
					statement: e,
					execInfo: t
				}]), s.breakLabel = i.breakLabelValue ?? -1, s.continueLabel = a[1].label;
			} else {
				let t = await q(e.expr, r, i);
				if (t == null || typeof t[Symbol.iterator] != "function") throw Error("Object in for..of is not iterable");
				P(i, 1), i.blocks ??= [], i.blocks.push({ vars: {} }), a = B([{
					statement: e,
					execInfo: {
						guard: !0,
						iterator: t[Symbol.iterator]()
					}
				}]);
			}
			break;
		case n: throw new O(await q(e.expr, r, i));
		case De: {
			if (!t.guard) {
				a = je(i, Le(i, e));
				break;
			}
			let n = N(i);
			switch (n.processingPhase) {
				case "error":
					switch (n.errorSource) {
						case "try":
							if (i.blocks.pop(), e.catchB) {
								if (n.statement.catchV) {
									let e = L(i);
									e.vars[n.statement.catchV.name] = n.errorToThrow instanceof O ? n.errorToThrow.errorObject : n.errorToThrow;
								}
								delete n.errorToThrow, n.processingPhase = "catch", a = Ue(i, n);
							} else n.statement.finallyB && (n.processingPhase = "finally", a = w(i, n));
							break;
						case "catch":
							i.blocks.pop(), n.processingPhase = "finally", a = w(i, n);
							break;
						case "finally":
							i.blocks.pop(), n.processingPhase = "postFinally", a = E(n);
							break;
					}
					break;
				case "try":
					n.processingPhase = "finally", a = e.finallyB ? w(i, n) : E(n);
					break;
				case "catch":
					n.processingPhase = "finally", a = e.finallyB ? w(i, n) : E(n);
					break;
				case "finally":
					n.processingPhase = "postFinally", a = E(n);
					break;
				case "postFinally":
					let t = i.tryBlocks.pop();
					switch (t.exitType) {
						case "break": {
							let e = C(i);
							if (e === void 0) throw Error("Missing loop scope");
							A(i), o = e.breakLabel;
							break;
						}
						case "continue": {
							let e = C(i);
							if (e === void 0) throw Error("Missing loop scope");
							o = e.continueLabel, A(i, !1);
							break;
						}
						case "return":
							i.tryBlocks && i.tryBlocks.length > 0 ? (i.blocks && i.blocks.length > 1 && i.blocks.pop(), o = i.tryBlocks[i.tryBlocks.length - 1].tryLabel) : o = -1;
							break;
					}
					if (t.errorToThrow) throw t.errorToThrow;
					break;
			}
			break;
		}
		case te:
			if (t.guard) A(i);
			else {
				let t = P(i);
				t.isSwitch = !0, i.blocks.push({ vars: {} });
				let n = await q(e.expr, r, i), o = -1;
				for (let t = 0; t < e.cases.length; t++) {
					let a = e.cases[t];
					if (a.caseE === void 0) {
						o = t;
						break;
					}
					if (await q(a.caseE, r, i) === n) {
						o = t;
						break;
					}
				}
				let s = [];
				if (o >= 0) for (let t = o; t < e.cases.length; t++) s.push(...e.cases[t].stmts);
				a = B([...D(s), x(e)]), t.breakLabel = a[a.length - 1].label;
			}
			break;
	}
	return t.removeBlockScope && i.blocks && i.blocks.length > 0 && i.blocks.pop(), {
		toUnshift: a,
		clearToLabel: o
	};
}
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 q(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 Ht(e) {
	let t = new h(e), n = null;
	try {
		n = t.parseStatements();
	} catch (n) {
		if (t.errors.length > 0) {
			let n = t.errors[0];
			R(new Me(`${n.code}(${n.line}, ${n.column}): ${t.errors[0].text}`, e, n.position));
		} else throw n;
	}
	if (!t.isEof) {
		let n = t.getTail();
		R(new Me("Invalid tail found", e, e.length - n.length + 1));
	}
	return n;
}
function Ut(e, t) {
	let n = e?.length ?? 0;
	if (n === 0) return [{
		type: l,
		expr: {
			type: y,
			args: [],
			statement: { type: M }
		}
	}];
	if (n === 1) {
		let n = e[0];
		if (n.type === S) return t && (n.expr.type === T || r(n.expr)) ? [i(n.expr)] : n.expr.type === y ? [{
			type: l,
			expr: n.expr
		}] : [{
			type: l,
			expr: {
				type: y,
				args: [],
				statement: e[0]
			}
		}];
		if (n.type === V) return [{
			type: l,
			expr: {
				type: y,
				args: [],
				statement: {
					type: b,
					stmts: [n]
				}
			}
		}];
		if (n.type === b) return n.stmts[0].type === S && n.stmts[0].expr.type === y ? [{
			type: l,
			expr: n.stmts[0].expr
		}] : [{
			type: l,
			expr: {
				type: y,
				args: [],
				statement: e[0]
			}
		}];
	}
	if (n > 1) return [{
		type: l,
		expr: {
			type: y,
			args: [],
			statement: {
				type: b,
				stmts: e
			}
		}
	}];
	return e;
	function r(e) {
		return (e.type === k || e.type === ie && e.member.type === j) && (r(e.obj) || e.obj.type === T);
	}
	function i(e) {
		let n = t.eventArgs ? t.eventArgs.map((e, t) => ({
			type: T,
			name: `__arg@@#__${t}__`
		})) : [];
		return t.eventArgs && t.eventArgs.forEach((e, n) => {
			t.localContext[`__arg@@#__${n}__`] = e;
		}), {
			type: l,
			expr: {
				type: y,
				args: n,
				statement: {
					type: S,
					expr: {
						type: z,
						obj: e,
						arguments: [...n]
					}
				}
			}
		};
	}
}
async function Wt(e, t, n) {
	return await Q(Ut(Ht(e)), t, n);
}
//#endregion
export { _t as a, Q as i, Ut as n, lt as o, Wt as r, nt as s, Ht as t };

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