import { Q as e, X as t, Z as n, p as r, z as i } from "./vue.runtime.esm-bundler-DpvJL-nX.js";
import { r as a, u as o } from "./dist-e0ylhlSV.js";
//#region ../core/dist/cloud/index.js
var s = class e {
	static DEFAULT_BASE_URL = "https://templatical.com";
	accessToken = null;
	expiresAt = null;
	_projectId = null;
	_tenantId = null;
	_tenantSlug = null;
	_testEmailConfig = null;
	_userConfig = null;
	url;
	baseUrl;
	requestOptions;
	onError;
	refreshPromise = null;
	static REFRESH_THRESHOLD_MS = 60 * 1e3;
	constructor(t) {
		this.url = t.url, this.baseUrl = (t.baseUrl ?? e.DEFAULT_BASE_URL).replace(/\/$/, ""), this.requestOptions = t.requestOptions ?? {}, this.onError = t.onError;
	}
	resolveUrl(e) {
		if (e.startsWith("http://") || e.startsWith("https://")) return e;
		let t = e.startsWith("/") ? e : `/${e}`;
		return `${this.baseUrl}${t}`;
	}
	get projectId() {
		if (!this._projectId) throw Error("Project ID not available. Call initialize() first.");
		return this._projectId;
	}
	get tenantId() {
		if (!this._tenantId) throw Error("Tenant ID not available. Call initialize() first.");
		return this._tenantId;
	}
	get tenantSlug() {
		if (!this._tenantSlug) throw Error("Tenant slug not available. Call initialize() first.");
		return this._tenantSlug;
	}
	get testEmailConfig() {
		return this._testEmailConfig;
	}
	get userConfig() {
		return this._userConfig;
	}
	get accessTokenValue() {
		return this.accessToken;
	}
	async initialize() {
		await this.ensureToken();
	}
	async ensureToken() {
		return this.accessToken && !this.isTokenExpiringSoon() ? this.accessToken : this.refreshToken();
	}
	isTokenExpiringSoon() {
		return this.expiresAt ? this.expiresAt.getTime() - Date.now() < e.REFRESH_THRESHOLD_MS : !0;
	}
	async refreshToken() {
		if (this.refreshPromise) return this.refreshPromise;
		this.refreshPromise = this.performRefresh();
		try {
			return await this.refreshPromise;
		} finally {
			this.refreshPromise = null;
		}
	}
	async performRefresh() {
		try {
			let e = this.requestOptions.method ?? "POST", t = {
				Accept: "application/json",
				...this.requestOptions.headers
			}, n = {
				method: e,
				headers: t,
				credentials: this.requestOptions.credentials ?? "include"
			};
			e === "POST" && this.requestOptions.body && (t["Content-Type"] = "application/json", n.body = JSON.stringify(this.requestOptions.body));
			let r = await fetch(this.url, n);
			if (!r.ok) throw new a(`Token refresh failed: ${r.status}`, r.status);
			let i = await r.json();
			if (!i.token || !i.expires_at || !i.project_id || !i.tenant) throw Error("Invalid token response: missing token, expires_at, project_id, or tenant");
			return this.accessToken = i.token, this.expiresAt = /* @__PURE__ */ new Date(i.expires_at * 1e3), this._projectId = i.project_id, this._tenantSlug = i.tenant, i.test_email?.allowed_emails && i.test_email?.signature ? this._testEmailConfig = {
				allowedEmails: i.test_email.allowed_emails,
				signature: i.test_email.signature
			} : this._testEmailConfig = null, i.user?.id && i.user?.name && i.user?.signature ? this._userConfig = {
				id: i.user.id,
				name: i.user.name,
				signature: i.user.signature
			} : this._userConfig = null, this.accessToken;
		} catch (e) {
			let t = e instanceof Error ? e : Error("Token refresh failed", { cause: e });
			throw this.onError?.(t), t;
		}
	}
	async authenticatedFetch(e, t = {}) {
		let n = await this.ensureToken(), r = this.resolveUrl(e), i = async (e) => fetch(r, {
			...t,
			headers: {
				...t.headers,
				Authorization: `Bearer ${e}`
			}
		}), a = await i(n);
		return a.status === 401 && (a = await i(await this.refreshToken())), a;
	}
};
function c(e, t) {
	return e.replace(/\{(\w+)\}/g, (e, n) => encodeURIComponent(t[n] ?? ""));
}
var l = "/api/v1/projects/{project}/tenants/{tenant}", u = `${l}/templates/{template}`, d = `${u}/ai`, f = `${l}/media`, p = `${f}/folders`, m = `${l}/saved-modules`, h = {
	health: "/api/v1/health",
	"projects.config": `${l}/config`,
	"broadcasting.auth": `${l}/broadcasting/auth`,
	"templates.store": `${l}/templates`,
	"templates.show": `${u}`,
	"templates.update": `${u}`,
	"templates.destroy": `${u}`,
	"templates.export": `${u}/export`,
	"templates.importFromBeefree": `${l}/templates/import/from-beefree`,
	"templates.sendTestEmail": `${u}/send-test-email`,
	"snapshots.index": `${u}/snapshots`,
	"snapshots.store": `${u}/snapshots`,
	"snapshots.show": `${u}/snapshots/{snapshot}`,
	"snapshots.restore": `${u}/snapshots/{snapshot}/restore`,
	"comments.index": `${u}/comments`,
	"comments.store": `${u}/comments`,
	"comments.update": `${u}/comments/{comment}`,
	"comments.destroy": `${u}/comments/{comment}`,
	"comments.resolve": `${u}/comments/{comment}/resolve`,
	"ai.generate": `${d}/generate`,
	"ai.conversationMessages": `${d}/conversation-messages`,
	"ai.suggestions": `${d}/suggestions`,
	"ai.rewriteText": `${d}/rewrite-text`,
	"ai.score": `${d}/score`,
	"ai.fixFinding": `${d}/fix-finding`,
	"ai.generateFromDesign": `${d}/generate-from-design`,
	"media.upload": `${f}/upload`,
	"media.browse": `${f}/browse`,
	"media.delete": `${f}/delete`,
	"media.move": `${f}/move`,
	"media.update": `${f}/{media}`,
	"media.replace": `${f}/{media}/replace`,
	"media.checkUsage": `${f}/check-usage`,
	"media.frequentlyUsed": `${f}/frequently-used`,
	"media.importFromUrl": `${f}/import-from-url`,
	"folders.index": `${p}`,
	"folders.store": `${p}`,
	"folders.update": `${p}/{mediaFolder}`,
	"folders.destroy": `${p}/{mediaFolder}`,
	"savedModules.index": `${m}`,
	"savedModules.store": `${m}`,
	"savedModules.update": `${m}/{savedModule}`,
	"savedModules.destroy": `${m}/{savedModule}`
}, g = class {
	constructor(e) {
		this.authManager = e;
	}
	authManager;
	get projectId() {
		return this.authManager.projectId;
	}
	get tenantSlug() {
		return this.authManager.tenantSlug;
	}
	get baseParams() {
		return {
			project: this.projectId,
			tenant: this.tenantSlug
		};
	}
	async request(e, t = {}) {
		let n = await this.authManager.authenticatedFetch(e, {
			...t,
			headers: {
				"Content-Type": "application/json",
				Accept: "application/json",
				...t.headers
			}
		});
		if (!n.ok) {
			let e = await n.json().catch(() => ({ message: `HTTP error ${n.status}` }));
			throw new a(this.extractFirstValidationError(e), n.status);
		}
		if (n.status !== 204) return (await n.json()).data;
	}
	extractFirstValidationError(e) {
		if (e.errors) {
			let t = Object.keys(e.errors)[0];
			if (t && e.errors[t]?.length > 0) return e.errors[t][0];
		}
		return e.message;
	}
	async createTemplate(e) {
		return this.request(c(h["templates.store"], this.baseParams), {
			method: "POST",
			body: JSON.stringify({ content: e })
		});
	}
	async getTemplate(e) {
		return this.request(c(h["templates.show"], {
			...this.baseParams,
			template: e
		}));
	}
	async updateTemplate(e, t) {
		return this.request(c(h["templates.update"], {
			...this.baseParams,
			template: e
		}), {
			method: "PUT",
			body: JSON.stringify({ content: t })
		});
	}
	async createSnapshot(e, t) {
		return this.request(c(h["snapshots.store"], {
			...this.baseParams,
			template: e
		}), {
			method: "POST",
			body: JSON.stringify({ content: t })
		});
	}
	async deleteTemplate(e) {
		return this.request(c(h["templates.destroy"], {
			...this.baseParams,
			template: e
		}), { method: "DELETE" });
	}
	async getSnapshots(e) {
		return this.request(c(h["snapshots.index"], {
			...this.baseParams,
			template: e
		}));
	}
	async restoreSnapshot(e, t) {
		return this.request(c(h["snapshots.restore"], {
			...this.baseParams,
			template: e,
			snapshot: t
		}), { method: "POST" });
	}
	async exportTemplate(e, t) {
		let n = t ? JSON.stringify({
			custom_fonts: t.customFonts,
			default_fallback: t.defaultFallback
		}) : void 0;
		return this.request(c(h["templates.export"], {
			...this.baseParams,
			template: e
		}), {
			method: "POST",
			body: n
		});
	}
	async sendTestEmail(e, t) {
		await this.request(c(h["templates.sendTestEmail"], {
			...this.baseParams,
			template: e
		}), {
			method: "POST",
			body: JSON.stringify(t)
		});
	}
	commentsUrl(e, t) {
		return t ? c(h["comments.update"], {
			...this.baseParams,
			template: e,
			comment: t
		}) : c(h["comments.index"], {
			...this.baseParams,
			template: e
		});
	}
	async getComments(e) {
		return this.request(this.commentsUrl(e));
	}
	async createComment(e, t, n) {
		return this.request(this.commentsUrl(e), {
			method: "POST",
			body: JSON.stringify(t),
			headers: n
		});
	}
	async updateComment(e, t, n, r) {
		return this.request(this.commentsUrl(e, t), {
			method: "PUT",
			body: JSON.stringify(n),
			headers: r
		});
	}
	async deleteComment(e, t, n, r) {
		return this.request(this.commentsUrl(e, t), {
			method: "DELETE",
			body: JSON.stringify(n),
			headers: r
		});
	}
	async resolveComment(e, t, n, r) {
		return this.request(c(h["comments.resolve"], {
			...this.baseParams,
			template: e,
			comment: t
		}), {
			method: "POST",
			body: JSON.stringify(n),
			headers: r
		});
	}
	async fetchConfig() {
		return this.request(c(h["projects.config"], this.baseParams));
	}
	async listModules(e) {
		let t = c(h["savedModules.index"], this.baseParams), n = e ? `?search=${encodeURIComponent(e)}` : "";
		return this.request(`${t}${n}`);
	}
	async createModule(e) {
		return this.request(c(h["savedModules.store"], this.baseParams), {
			method: "POST",
			body: JSON.stringify(e)
		});
	}
	async updateModule(e, t) {
		return this.request(c(h["savedModules.update"], {
			...this.baseParams,
			savedModule: e
		}), {
			method: "PUT",
			body: JSON.stringify(t)
		});
	}
	async deleteModule(e) {
		return this.request(c(h["savedModules.destroy"], {
			...this.baseParams,
			savedModule: e
		}), { method: "DELETE" });
	}
};
function _(e) {
	return {
		host: e.host,
		port: e.port,
		appKey: e.app_key
	};
}
var v = class {
	pusher = null;
	authManager;
	config;
	onError;
	constructor(e) {
		this.authManager = e.authManager, this.config = e.config, this.onError = e.onError;
	}
	async connect() {
		if (this.pusher) return;
		let e;
		try {
			({default: e} = await import("pusher-js"));
		} catch {
			throw Error("Cloud features require the optional peer dependency 'pusher-js'. Install it with: npm install pusher-js");
		}
		let { host: t, port: n, appKey: r } = this.config, i = this.authManager.resolveUrl(c(h["broadcasting.auth"], {
			project: this.authManager.projectId,
			tenant: this.authManager.tenantSlug
		}));
		this.pusher = new e(r, {
			wsHost: t,
			wsPort: n,
			wssPort: n,
			forceTLS: !0,
			disableStats: !0,
			enabledTransports: ["ws", "wss"],
			cluster: "",
			channelAuthorization: {
				transport: "ajax",
				endpoint: i,
				headers: {
					Authorization: `Bearer ${this.authManager.accessTokenValue}`,
					Accept: "application/json"
				},
				params: {
					user_id: this.authManager.userConfig?.id ?? "",
					user_name: this.authManager.userConfig?.name ?? "",
					user_signature: this.authManager.userConfig?.signature ?? ""
				}
			}
		}), this.pusher.connection.bind("error", (e) => {
			this.onError?.(e instanceof Error ? e : /* @__PURE__ */ Error("WebSocket connection error"));
		});
	}
	subscribePresence(e) {
		if (!this.pusher) throw Error("WebSocketClient not connected. Call connect() first.");
		return this.pusher.subscribe(e);
	}
	unsubscribe(e) {
		this.pusher?.unsubscribe(e);
	}
	getChannel(e) {
		return this.pusher?.channel(e);
	}
	disconnect() {
		this.pusher &&= (this.pusher.disconnect(), null);
	}
	getSocketId() {
		return this.pusher?.connection.socket_id ?? null;
	}
	get isConnected() {
		return this.pusher?.connection.state === "connected";
	}
};
function y(e, t) {
	let { operation: n, data: r } = t;
	switch (n) {
		case "add_block":
			e.addBlock(r.block, r.section_id, r.column_index, r.index);
			break;
		case "update_block":
			e.updateBlock(r.block_id, r.updates);
			break;
		case "delete_block":
			e.removeBlock(r.block_id);
			break;
		case "move_block":
			e.moveBlock(r.block_id, r.index, r.section_id, r.column_index);
			break;
		case "update_settings":
			e.updateSettings(r.updates);
			break;
		case "set_content":
			e.setContent(r.content);
			break;
		case "update_block_style":
			e.updateBlock(r.block_id, { styles: r.styles });
			break;
	}
}
function b(e) {
	let i = new g(e.authManager), s = t({
		template: null,
		content: o(e.defaultFontFamily, e.templateDefaults),
		selectedBlockId: null,
		viewport: "desktop",
		darkMode: !1,
		previewMode: !1,
		isDirty: !1,
		isSaving: !1,
		isLoading: !1,
		uiTheme: "auto"
	}), c = r({
		get: () => s.content,
		set: (e) => {
			s.content = e, s.isDirty = !0;
		}
	}), l = r(() => s.selectedBlockId ? d(s.content.blocks, s.selectedBlockId) : null), u = r(() => {
		let e = /* @__PURE__ */ new Set(), t = s.template?.content?.blocks;
		if (!t) return e;
		for (let n of t) if (e.add(n.id), n.type === "section") for (let t of n.children) for (let n of t) e.add(n.id);
		return e;
	});
	function d(e, t) {
		for (let n of e) {
			if (n.id === t) return n;
			if (n.type === "section") for (let e of n.children) {
				let n = d(e, t);
				if (n) return n;
			}
		}
		return null;
	}
	function f(e, t, n = { blocks: e }) {
		for (let r = 0; r < e.length; r++) {
			let i = e[r];
			if (i.id === t) return n;
			if (i.type === "section") for (let e = 0; e < i.children.length; e++) {
				let n = f(i.children[e], t, {
					blocks: i.children[e],
					sectionId: i.id,
					columnIndex: e
				});
				if (n) return n;
			}
		}
		return null;
	}
	function p(t) {
		return e.lockedBlocks?.value.has(t) ?? !1;
	}
	function m(e, t = !0) {
		s.content = e, t && (s.isDirty = !0);
	}
	function h(e) {
		e && p(e) || (s.selectedBlockId = e);
	}
	function _(e) {
		s.viewport = e;
	}
	function v(e) {
		s.darkMode = e;
	}
	function y(e) {
		s.uiTheme = e;
	}
	function b(e) {
		s.previewMode = e, e && (s.selectedBlockId = null);
	}
	function x(e, t) {
		if (p(e)) return;
		let n = d(s.content.blocks, e);
		n && (Object.assign(n, t), s.isDirty = !0);
	}
	function S(e) {
		s.content.settings = {
			...s.content.settings,
			...e
		}, s.isDirty = !0;
	}
	function C(e, t, n = 0, r) {
		if (t) {
			let i = d(s.content.blocks, t);
			if (i && i.type === "section") {
				i.children[n] = i.children[n] || [];
				let t = i.children[n];
				r !== void 0 && r < t.length ? t.splice(r, 0, e) : t.push(e);
			}
		} else r !== void 0 && r < s.content.blocks.length ? s.content.blocks.splice(r, 0, e) : s.content.blocks.push(e);
		s.isDirty = !0;
	}
	function w(e) {
		if (p(e)) return;
		let t = f(s.content.blocks, e);
		if (t) {
			let n = t.blocks.findIndex((t) => t.id === e);
			n !== -1 && (t.blocks.splice(n, 1), s.selectedBlockId === e && (s.selectedBlockId = null), s.isDirty = !0);
		}
	}
	function T(e, t, n, r = 0) {
		let i = f(s.content.blocks, e);
		if (!i) return;
		let a = i.blocks.findIndex((t) => t.id === e);
		if (a === -1) return;
		let [o] = i.blocks.splice(a, 1);
		if (n) {
			let e = d(s.content.blocks, n);
			e && e.type === "section" && (e.children[r] = e.children[r] || [], e.children[r].splice(t, 0, o));
		} else s.content.blocks.splice(t, 0, o);
		s.isDirty = !0;
	}
	async function E(t) {
		s.isLoading = !0;
		try {
			t && (s.content = t);
			let e = await i.createTemplate(s.content);
			return s.template = e, s.isDirty = !1, e;
		} catch (t) {
			throw e.onError?.(t), t;
		} finally {
			s.isLoading = !1;
		}
	}
	async function D(t) {
		s.isLoading = !0;
		try {
			let e = await i.getTemplate(t);
			return s.template = e, s.content = e.content, s.isDirty = !1, e;
		} catch (t) {
			throw e.onError?.(t), t;
		} finally {
			s.isLoading = !1;
		}
	}
	async function O() {
		if (!s.template?.id) throw new a("No template loaded. Call create() or load() before saving.");
		s.isSaving = !0;
		try {
			let e = await i.updateTemplate(s.template.id, s.content);
			return s.template = e, s.isDirty = !1, e;
		} catch (t) {
			throw e.onError?.(t), t;
		} finally {
			s.isSaving = !1;
		}
	}
	async function k() {
		if (s.template?.id) try {
			await i.createSnapshot(s.template.id, s.content);
		} catch (t) {
			throw e.onError?.(t), t;
		}
	}
	function A() {
		return s.template?.id !== void 0;
	}
	function j() {
		s.isDirty = !0;
	}
	return {
		state: n(s),
		content: c,
		selectedBlock: l,
		savedBlockIds: u,
		isBlockLocked: p,
		setContent: m,
		selectBlock: h,
		setViewport: _,
		setDarkMode: v,
		setUiTheme: y,
		setPreviewMode: b,
		updateBlock: x,
		updateSettings: S,
		addBlock: C,
		removeBlock: w,
		moveBlock: T,
		create: E,
		load: D,
		save: O,
		createSnapshot: k,
		hasTemplate: A,
		markDirty: j
	};
}
var x = 0;
function S() {
	return `msg_${Date.now()}_${++x}`;
}
function C(t) {
	let { authManager: n, getTemplateId: r, onApply: i, onError: a } = t, o = e([]), s = e(!1), l = e(!1), u = e(null), d = e(null), f = e(null), p = e(null), m = e(null), g = e(null), _ = e(!1), v = e([]), y = e(!1);
	function b(e, t) {
		let n = o.value.findIndex((t) => t.id === e);
		if (n === -1) return;
		let r = {
			...o.value[n],
			...t
		};
		o.value = [
			...o.value.slice(0, n),
			r,
			...o.value.slice(n + 1)
		];
	}
	async function x() {
		let e = r();
		if (e) {
			l.value = !0;
			try {
				let t = c(h["ai.conversationMessages"], {
					project: n.projectId,
					tenant: n.tenantSlug,
					template: e
				}), r = await n.authenticatedFetch(t, {
					method: "GET",
					headers: { Accept: "application/json" }
				});
				if (!r.ok) return;
				let i = await r.json();
				i.conversation_id && (f.value = i.conversation_id), Array.isArray(i.data) && i.data.length > 0 && (o.value = i.data.map((e) => ({
					id: e.id,
					role: e.role,
					content: e.content,
					timestamp: new Date(e.created_at).getTime()
				})));
			} catch {} finally {
				l.value = !1;
			}
		}
	}
	async function C(e, t) {
		let i = r();
		if (i) {
			y.value = !0;
			try {
				let r = c(h["ai.suggestions"], {
					project: n.projectId,
					tenant: n.tenantSlug,
					template: i
				}), a = await n.authenticatedFetch(r, {
					method: "POST",
					headers: {
						"Content-Type": "application/json",
						Accept: "text/event-stream"
					},
					body: JSON.stringify({
						current_content: e,
						merge_tags: t.map((e) => ({
							label: e.label,
							value: e.value
						}))
					})
				});
				if (!a.ok) return;
				let o = a.body?.getReader();
				if (!o) return;
				let s = new TextDecoder(), l = "";
				for (;;) {
					let { done: e, value: t } = await o.read();
					if (e) break;
					l += s.decode(t, { stream: !0 });
					let n = l.split("\n");
					l = n.pop() ?? "";
					for (let e of n) {
						if (!e.startsWith("data: ")) continue;
						let t;
						try {
							t = JSON.parse(e.slice(6));
						} catch {
							continue;
						}
						t.type === "done" && Array.isArray(t.suggestions) && (v.value = t.suggestions.slice(0, 3));
					}
				}
			} catch {} finally {
				y.value = !1;
			}
		}
	}
	async function w(e, t, l) {
		let y = r();
		if (!y) throw Error("Template must be saved before using AI generation");
		s.value = !0, u.value = null, d.value = null, v.value = [];
		let x = S();
		o.value = [...o.value, {
			id: x,
			role: "user",
			content: e,
			timestamp: Date.now()
		}];
		let C = S();
		o.value = [...o.value, {
			id: C,
			role: "assistant",
			content: "",
			timestamp: Date.now()
		}];
		try {
			let r = c(h["ai.generate"], {
				project: n.projectId,
				tenant: n.tenantSlug,
				template: y
			}), a = await n.authenticatedFetch(r, {
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					Accept: "text/event-stream"
				},
				body: JSON.stringify({
					prompt: e,
					current_content: t,
					merge_tags: l.map((e) => ({
						label: e.label,
						value: e.value
					})),
					conversation_id: f.value
				})
			});
			if (!a.ok) {
				let e = await a.json().catch(() => null);
				throw a.status === 403 ? Error("ai_generation_not_available") : Error(e?.message || "Failed to generate template");
			}
			let s = a.body?.getReader();
			if (!s) throw Error("Failed to read stream");
			let d = new TextDecoder(), v = "", x = null;
			for (;;) {
				let { done: e, value: n } = await s.read();
				if (e) break;
				v += d.decode(n, { stream: !0 });
				let r = v.split("\n");
				v = r.pop() ?? "";
				for (let e of r) {
					if (!e.startsWith("data: ")) continue;
					let n = e.slice(6), r;
					try {
						r = JSON.parse(n);
					} catch {
						continue;
					}
					if (r.type === "text") b(C, { content: (o.value.find((e) => e.id === C)?.content ?? "") + r.text });
					else if (r.type === "error") throw Error(r.message || "Failed to generate template");
					else r.type === "done" && (r.conversation_id && (f.value = r.conversation_id), b(C, { content: r.text }), x = r.content ?? null, x ? (m.value = t, g.value = x, p.value = C, _.value = !1, i?.(x)) : u.value = "ai_apply_failed");
				}
			}
			return x;
		} catch (t) {
			let n = t instanceof Error ? t : Error("Failed to generate template", { cause: t });
			return u.value = n.message, d.value = e, a?.(n), o.value = o.value.filter((e) => e.id !== x && e.id !== C), null;
		} finally {
			s.value = !1;
		}
	}
	function T() {
		_.value ? (g.value && i?.(g.value), _.value = !1) : (m.value && i?.(m.value), _.value = !0);
	}
	function E() {
		o.value = [], f.value = null, u.value = null, p.value = null, m.value = null, g.value = null, _.value = !1;
	}
	return {
		messages: o,
		isGenerating: s,
		isLoadingHistory: l,
		isLastChangeReverted: _,
		lastApplyMessageId: p,
		error: u,
		failedPrompt: d,
		suggestions: v,
		isLoadingSuggestions: y,
		sendPrompt: w,
		toggleLastRevert: T,
		loadConversation: x,
		loadSuggestions: C,
		clearChat: E
	};
}
function w(e) {
	function t(t) {
		return e === !1 ? !1 : e?.[t] !== !1;
	}
	return {
		isFeatureEnabled: t,
		hasAnyMenuFeature: r(() => t("chat") || t("scoring") || t("designToTemplate"))
	};
}
function T(t) {
	let { authManager: n, getTemplateId: r } = t, i = e(!1), a = e(null), o = e(null), s = e(null), l = e(""), u = e(null);
	async function d(e, t) {
		let s = r();
		if (!s) return null;
		i.value = !0, o.value = null, a.value = null;
		try {
			let r = c(h["ai.score"], {
				project: n.projectId,
				tenant: n.tenantSlug,
				template: s
			}), i = await n.authenticatedFetch(r, {
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					Accept: "text/event-stream"
				},
				body: JSON.stringify({
					current_content: e,
					merge_tags: t.map((e) => ({
						label: e.label,
						value: e.value
					}))
				})
			});
			if (!i.ok) {
				if (i.status === 403) throw Error("ai_generation_not_available");
				let e = await i.json().catch(() => null);
				throw Error(e?.message || "Failed to score template");
			}
			let o = i.body?.getReader();
			if (!o) throw Error("Failed to read stream");
			let l = new TextDecoder(), u = "", d = null;
			for (;;) {
				let { done: e, value: t } = await o.read();
				if (e) break;
				u += l.decode(t, { stream: !0 });
				let n = u.split("\n");
				u = n.pop() ?? "";
				for (let e of n) {
					if (!e.startsWith("data: ")) continue;
					let t;
					try {
						t = JSON.parse(e.slice(6));
					} catch {
						continue;
					}
					if (t.type === "error") throw Error(t.message || "Failed to score template");
					t.type === "done" && (d = t.result ?? null);
				}
			}
			if (d) for (let [e, t] of Object.entries(d.categories)) for (let n of t.findings) n.category = e;
			return a.value = d, d;
		} catch (e) {
			return o.value = e instanceof Error ? e.message : "Failed to score template", null;
		} finally {
			i.value = !1;
		}
	}
	async function f(e, t, i) {
		let a = r();
		if (!a) return null;
		s.value = t.id, l.value = "", u.value = null;
		try {
			let r = c(h["ai.fixFinding"], {
				project: n.projectId,
				tenant: n.tenantSlug,
				template: a
			}), o = await n.authenticatedFetch(r, {
				method: "POST",
				headers: {
					"Content-Type": "application/json",
					Accept: "text/event-stream"
				},
				body: JSON.stringify({
					content: e,
					finding: {
						id: t.id,
						message: t.message,
						suggestion: t.suggestion,
						category: t.category
					},
					merge_tags: i.map((e) => ({
						label: e.label,
						value: e.value
					}))
				})
			});
			if (!o.ok) {
				if (o.status === 403) throw Error("ai_generation_not_available");
				let e = await o.json().catch(() => null);
				throw Error(e?.message || "Failed to fix finding");
			}
			let s = o.body?.getReader();
			if (!s) throw Error("Failed to read stream");
			let u = new TextDecoder(), d = "", f = null;
			for (;;) {
				let { done: e, value: t } = await s.read();
				if (e) break;
				d += u.decode(t, { stream: !0 });
				let n = d.split("\n");
				d = n.pop() ?? "";
				for (let e of n) {
					if (!e.startsWith("data: ")) continue;
					let t;
					try {
						t = JSON.parse(e.slice(6));
					} catch {
						continue;
					}
					if (t.type === "text") l.value += t.text;
					else if (t.type === "error") throw Error(t.message || "Failed to fix finding");
					else t.type === "done" && (f = t.content ?? null);
				}
			}
			return f;
		} catch (e) {
			return u.value = e instanceof Error ? e.message : "Failed to fix finding", null;
		} finally {
			s.value = null;
		}
	}
	function p(e, t) {
		if (!a.value) return;
		let n = a.value.categories[e];
		n && (n.findings = n.findings.filter((e) => e.id !== t));
	}
	function m() {
		i.value = !1, a.value = null, o.value = null, s.value = null, l.value = "", u.value = null;
	}
	return {
		isScoring: i,
		scoringResult: a,
		error: o,
		fixingFindingId: s,
		fixStreamingText: l,
		fixError: u,
		score: d,
		fixFinding: f,
		removeFinding: p,
		reset: m
	};
}
function E(t) {
	let { authManager: n, getTemplateId: r, onApply: i, onError: a } = t, o = e(!1), s = e(null);
	async function l(e) {
		let t = r();
		if (!t) throw Error("Template must be saved before using design reference");
		o.value = !0, s.value = null;
		try {
			let r = new FormData();
			e.prompt && r.append("prompt", e.prompt), e.imageUpload && r.append("image_upload", e.imageUpload), e.pdfUpload && r.append("pdf_upload", e.pdfUpload);
			let a = c(h["ai.generateFromDesign"], {
				project: n.projectId,
				tenant: n.tenantSlug,
				template: t
			}), o = await n.authenticatedFetch(a, {
				method: "POST",
				headers: { Accept: "text/event-stream" },
				body: r
			});
			if (!o.ok) {
				let e = await o.json().catch(() => null);
				throw o.status === 403 ? Error("ai_generation_not_available") : Error(e?.message || "Failed to generate template from design");
			}
			let s = o.body?.getReader();
			if (!s) throw Error("Failed to read stream");
			let l = new TextDecoder(), u = "", d = null;
			for (;;) {
				let { done: e, value: t } = await s.read();
				if (e) break;
				u += l.decode(t, { stream: !0 });
				let n = u.split("\n");
				u = n.pop() ?? "";
				for (let e of n) {
					if (!e.startsWith("data: ")) continue;
					let t = e.slice(6), n;
					try {
						n = JSON.parse(t);
					} catch {
						continue;
					}
					if (n.type === "error") throw Error(n.message || "Failed to generate template from design");
					n.type === "done" && (d = n.content ?? null, d && i?.(d));
				}
			}
			return d;
		} catch (e) {
			let t = e instanceof Error ? e : Error("Failed to generate template from design", { cause: e });
			return s.value = t.message, a?.(t), null;
		} finally {
			o.value = !1;
		}
	}
	function u() {
		o.value = !1, s.value = null;
	}
	return {
		isGenerating: o,
		error: s,
		generate: l,
		reset: u
	};
}
function D(t) {
	let { authManager: n, getTemplateId: i, getSocketId: a, onComment: o, onError: s, hasCommentingFeature: c } = t, l = new g(n), u = e([]), d = e(!1), f = e(!1), p = r(() => (c?.() ?? !1) && n.userConfig !== null), m = r(() => {
		let e = 0;
		for (let t of u.value) e += 1 + (t.replies?.length ?? 0);
		return e;
	}), h = r(() => u.value.filter((e) => !e.resolved_at).length), _ = r(() => {
		let e = /* @__PURE__ */ new Map();
		for (let t of u.value) t.block_id && e.set(t.block_id, (e.get(t.block_id) ?? 0) + 1 + (t.replies?.length ?? 0));
		return e;
	});
	function v() {
		let e = n.userConfig;
		if (!e) throw Error("User config not available");
		return {
			user_id: e.id,
			user_name: e.name,
			user_signature: e.signature
		};
	}
	function y() {
		let e = a?.();
		if (e) return { "X-Socket-ID": e };
	}
	function b(e, t) {
		o?.({
			type: e,
			comment: t
		});
	}
	function x(e) {
		for (let t of u.value) {
			if (t.id === e) return t;
			for (let n of t.replies ?? []) if (n.id === e) return n;
		}
		return null;
	}
	async function S() {
		let e = i();
		if (e) {
			d.value = !0;
			try {
				u.value = await l.getComments(e);
			} catch (e) {
				let t = e instanceof Error ? e : Error("Failed to load comments", { cause: e });
				s?.(t);
			} finally {
				d.value = !1;
			}
		}
	}
	async function C(e, t, n) {
		let r = i();
		if (!r) return null;
		f.value = !0;
		try {
			let i = await l.createComment(r, {
				body: e,
				block_id: t,
				parent_id: n,
				...v()
			}, y());
			if (n) {
				let e = x(n);
				e && (e.replies = [...e.replies ?? [], i]);
			} else u.value = [...u.value, i];
			return b("created", i), i;
		} catch (e) {
			let t = e instanceof Error ? e : Error("Failed to create comment", { cause: e });
			return s?.(t), null;
		} finally {
			f.value = !1;
		}
	}
	async function w(e, t) {
		let n = i();
		if (!n) return null;
		f.value = !0;
		try {
			let r = await l.updateComment(n, e, {
				body: t,
				...v()
			}, y());
			return A(e, r), b("updated", r), r;
		} catch (e) {
			let t = e instanceof Error ? e : Error("Failed to update comment", { cause: e });
			return s?.(t), null;
		} finally {
			f.value = !1;
		}
	}
	async function T(e) {
		let t = i();
		if (!t) return !1;
		let n = x(e);
		if (!n) return !1;
		let r = {
			...n,
			replies: [...n.replies ?? []]
		};
		f.value = !0;
		try {
			if (await l.deleteComment(t, e, v(), y()), n.parent_id) {
				let t = x(n.parent_id);
				t && (t.replies = (t.replies ?? []).filter((t) => t.id !== e));
			} else u.value = u.value.filter((t) => t.id !== e);
			return b("deleted", r), !0;
		} catch (e) {
			let t = e instanceof Error ? e : Error("Failed to delete comment", { cause: e });
			return s?.(t), !1;
		} finally {
			f.value = !1;
		}
	}
	async function E(e) {
		let t = i();
		if (!t) return null;
		f.value = !0;
		try {
			let n = await l.resolveComment(t, e, v(), y());
			return A(e, n), b(n.resolved_at ? "resolved" : "unresolved", n), n;
		} catch (e) {
			let t = e instanceof Error ? e : Error("Failed to toggle comment resolution", { cause: e });
			return s?.(t), null;
		} finally {
			f.value = !1;
		}
	}
	function D(e) {
		if (e.parent_id) {
			let t = x(e.parent_id);
			t && (t.replies = [...t.replies ?? [], e]);
		} else u.value = [...u.value, e];
		b("created", e);
	}
	function O(e) {
		A(e.id, e), b("updated", e);
	}
	function k(e, t) {
		let n = x(e), r = n ? {
			...n,
			replies: [...n.replies ?? []]
		} : null;
		if (t) {
			let n = x(t);
			n && (n.replies = (n.replies ?? []).filter((t) => t.id !== e));
		} else u.value = u.value.filter((t) => t.id !== e);
		r && b("deleted", r);
	}
	function A(e, t) {
		for (let n = 0; n < u.value.length; n++) {
			if (u.value[n].id === e) {
				u.value = [
					...u.value.slice(0, n),
					{
						...t,
						replies: u.value[n].replies
					},
					...u.value.slice(n + 1)
				];
				return;
			}
			let r = u.value[n].replies ?? [];
			for (let i = 0; i < r.length; i++) if (r[i].id === e) {
				let e = [
					...r.slice(0, i),
					t,
					...r.slice(i + 1)
				];
				u.value = [
					...u.value.slice(0, n),
					{
						...u.value[n],
						replies: e
					},
					...u.value.slice(n + 1)
				];
				return;
			}
		}
	}
	return {
		comments: u,
		isLoading: d,
		isSubmitting: f,
		isEnabled: p,
		commentCountByBlock: _,
		totalCount: m,
		unresolvedCount: h,
		loadComments: S,
		addComment: C,
		editComment: w,
		removeComment: T,
		toggleResolve: E,
		applyRemoteCreate: D,
		applyRemoteUpdate: O,
		applyRemoteDelete: k
	};
}
function O(e) {
	let { comments: t, channel: n } = e;
	i(n, (e, n) => {
		n && n.unbind("comment-broadcast"), e && e.bind("comment-broadcast", (e) => {
			k(t, e);
		});
	});
}
function k(e, t) {
	switch (t.action) {
		case "comment_created":
			e.applyRemoteCreate(t.comment);
			break;
		case "comment_updated":
			e.applyRemoteUpdate(t.comment);
			break;
		case "comment_deleted":
			e.applyRemoteDelete(t.comment.id, t.comment.parent_id);
			break;
		case "comment_resolved":
		case "comment_unresolved":
			e.applyRemoteUpdate(t.comment);
			break;
	}
}
var A = [
	"#3b82f6",
	"#ef4444",
	"#10b981",
	"#f59e0b",
	"#8b5cf6",
	"#ec4899",
	"#06b6d4",
	"#f97316",
	"#6366f1",
	"#14b8a6"
];
function j(t) {
	let { authManager: n, editor: a, channel: o } = t, s = e([]), c = e(/* @__PURE__ */ new Map()), l = 0, u = !1, d = r(() => n.userConfig?.id ?? "");
	function f() {
		let e = A[l % A.length];
		return l++, e;
	}
	function p(e) {
		if (e.id === d.value || s.value.some((t) => t.id === e.id)) return;
		let t = {
			id: e.id,
			name: e.name,
			color: f(),
			selectedBlockId: null
		};
		return s.value = [...s.value, t], t;
	}
	function m(e) {
		let t = new Map(c.value);
		for (let [n, r] of t) r.id === e && t.delete(n);
		c.value = t, s.value = s.value.filter((t) => t.id !== e);
	}
	function h(e) {
		let t = s.value.find((t) => t.id === e.userId);
		if (!t) return;
		s.value = s.value.map((t) => t.id === e.userId ? {
			...t,
			selectedBlockId: e.blockId
		} : t);
		let n = new Map(c.value);
		for (let [t, r] of n) r.id === e.userId && n.delete(t);
		n.set(e.blockId, {
			...t,
			selectedBlockId: e.blockId
		}), c.value = n, a.state.selectedBlockId === e.blockId && a.selectBlock(null);
	}
	function g(e) {
		let t = new Map(c.value), n = t.get(e.blockId);
		t.delete(e.blockId), c.value = t, n && (s.value = s.value.map((e) => e.id === n.id ? {
			...e,
			selectedBlockId: null
		} : e));
	}
	function _(e) {
		u = !0;
		try {
			y(a, e);
		} finally {
			u = !1;
		}
	}
	function v(e) {
		!o.value || u || o.value.trigger("client-operation", e);
	}
	function b(e) {
		o.value && o.value.trigger("client-block_locked", {
			blockId: e,
			userId: d.value
		});
	}
	function x(e) {
		o.value && o.value.trigger("client-block_unlocked", { blockId: e });
	}
	return i(() => a.state.selectedBlockId, (e, t) => {
		u || (t && x(t), e && b(e));
	}), i(o, (e, n) => {
		if (n && (n.unbind("pusher:member_added"), n.unbind("pusher:member_removed"), n.unbind("client-block_locked"), n.unbind("client-block_unlocked"), n.unbind("client-operation"), n.unbind("mcp-operation")), !e) {
			s.value = [], c.value = /* @__PURE__ */ new Map(), l = 0;
			return;
		}
		let r = e.members;
		r && r.each((e) => {
			p(e.info);
		}), e.bind("pusher:member_added", (e) => {
			let n = p(e.info);
			n && t.onCollaboratorJoined?.(n);
		}), e.bind("pusher:member_removed", (e) => {
			let n = s.value.find((t) => t.id === e.id);
			m(e.id), n && t.onCollaboratorLeft?.(n);
		}), e.bind("client-block_locked", (e) => {
			h(e);
			let n = s.value.find((t) => t.id === e.userId);
			n && t.onBlockLocked?.({
				blockId: e.blockId,
				collaborator: n
			});
		}), e.bind("client-block_unlocked", (e) => {
			let n = c.value.get(e.blockId);
			g(e), n && t.onBlockUnlocked?.({
				blockId: e.blockId,
				collaborator: n
			});
		}), e.bind("client-operation", (e) => {
			_(e);
		}), e.bind("mcp-operation", (e) => {
			_(e);
		});
	}), {
		collaborators: s,
		lockedBlocks: c,
		_broadcastOperation: v,
		_isProcessingRemoteOperation: () => u
	};
}
function M(e, t) {
	let n = e.addBlock, r = e.updateBlock, i = e.removeBlock, a = e.moveBlock, o = e.updateSettings, s = e.setContent;
	e.addBlock = (e, r, i) => {
		n(e, r, i), t._broadcastOperation({
			operation: "add_block",
			data: {
				block: e,
				section_id: r,
				column_index: i
			},
			timestamp: Date.now()
		});
	}, e.updateBlock = (e, n) => {
		r(e, n), t._broadcastOperation({
			operation: "update_block",
			data: {
				block_id: e,
				updates: n
			},
			timestamp: Date.now()
		});
	}, e.removeBlock = (e) => {
		i(e), t._broadcastOperation({
			operation: "delete_block",
			data: { block_id: e },
			timestamp: Date.now()
		});
	}, e.moveBlock = (e, n, r, i) => {
		a(e, n, r, i), t._broadcastOperation({
			operation: "move_block",
			data: {
				block_id: e,
				index: n,
				section_id: r,
				column_index: i
			},
			timestamp: Date.now()
		});
	}, e.updateSettings = (e) => {
		o(e), t._broadcastOperation({
			operation: "update_settings",
			data: { updates: e },
			timestamp: Date.now()
		});
	}, e.setContent = (e, n) => {
		s(e, n), t._broadcastOperation({
			operation: "set_content",
			data: { content: e },
			timestamp: Date.now()
		});
	};
}
function N(t) {
	let { authManager: n, onError: r } = t, i = e(null), a = e(!1), o = null, s = null;
	async function c(e, t) {
		if (o) return;
		o = new v({
			authManager: n,
			config: t,
			onError: r
		}), await o.connect(), s = `presence-template.${e}`;
		let c = o.subscribePresence(s);
		c.bind("pusher:subscription_succeeded", () => {
			a.value = !0, i.value = c;
		}), c.bind("pusher:subscription_error", (e) => {
			a.value = !1, i.value = null, r?.(e instanceof Error ? e : /* @__PURE__ */ Error("Failed to subscribe to template channel"));
		});
	}
	function l() {
		s && o && o.unsubscribe(s), o?.disconnect(), o = null, s = null, i.value = null, a.value = !1;
	}
	function u() {
		return o?.getSocketId() ?? null;
	}
	return {
		channel: i,
		isConnected: a,
		connect: c,
		disconnect: l,
		getSocketId: u
	};
}
function P(t) {
	let n = new g(t.authManager), r = e([]), i = e(!1);
	async function a(e) {
		i.value = !0;
		try {
			r.value = await n.listModules(e);
		} catch (e) {
			throw t.onError?.(e), e;
		} finally {
			i.value = !1;
		}
	}
	async function o(e, i) {
		try {
			let t = await n.createModule({
				name: e,
				content: i
			});
			return r.value = [t, ...r.value], t;
		} catch (e) {
			throw t.onError?.(e), e;
		}
	}
	async function s(e, i) {
		try {
			let t = await n.updateModule(e, i);
			return r.value = r.value.map((n) => n.id === e ? t : n), t;
		} catch (e) {
			throw t.onError?.(e), e;
		}
	}
	async function c(e) {
		try {
			await n.deleteModule(e), r.value = r.value.filter((t) => t.id !== e);
		} catch (e) {
			throw t.onError?.(e), e;
		}
	}
	return {
		modules: r,
		isLoading: i,
		loadModules: a,
		createModule: o,
		updateModule: s,
		deleteModule: c
	};
}
function F(t) {
	let n = new g(t.authManager), r = e([]), i = e(!1), a = e(!1);
	async function o() {
		i.value = !0;
		try {
			r.value = await n.getSnapshots(t.templateId);
		} catch (e) {
			throw t.onError?.(e), e;
		} finally {
			i.value = !1;
		}
	}
	async function s(e) {
		a.value = !0;
		try {
			let r = await n.restoreSnapshot(t.templateId, e);
			return t.onRestore?.(r), r;
		} catch (e) {
			throw t.onError?.(e), e;
		} finally {
			a.value = !1;
		}
	}
	return {
		snapshots: r,
		isLoading: i,
		isRestoring: a,
		loadSnapshots: o,
		restoreSnapshot: s
	};
}
function I(t) {
	let { authManager: n, getTemplateId: a, save: o, exportHtml: s, onError: c, isAuthReady: l, onBeforeTestEmail: u } = t, d = new g(n), f = e(!1), p = e(null), m = e(null);
	l && i(l, (e) => {
		e && (m.value = n.testEmailConfig);
	}, { immediate: !0 });
	let h = r(() => m.value !== null), _ = r(() => m.value?.allowedEmails ?? []);
	async function v(e) {
		if (!m.value) throw Error("Test email is not enabled for this project");
		let t = a();
		if (!t) throw Error("Template must be saved before sending a test email");
		f.value = !0, p.value = null;
		try {
			await o();
			let { html: n } = await s(t);
			u && (n = await u(n)), await d.sendTestEmail(t, {
				recipient: e,
				html: n,
				allowed_emails: m.value.allowedEmails,
				signature: m.value.signature
			});
		} catch (e) {
			let t = e instanceof Error ? e : Error("Failed to send test email", { cause: e });
			throw p.value = t.message, c?.(t), t;
		} finally {
			f.value = !1;
		}
	}
	return {
		isEnabled: h,
		allowedEmails: _,
		isSending: f,
		error: p,
		sendTestEmail: v
	};
}
function L(e) {
	let { authManager: t, getFontsConfig: n, canUseCustomFonts: r } = e, i = new g(t);
	function a() {
		let e = n?.();
		return {
			customFonts: (r?.() ?? !0) && e?.customFonts ? e.customFonts : [],
			defaultFallback: e?.defaultFallback ?? "Arial, sans-serif"
		};
	}
	async function o(e) {
		let t = a(), n = await i.exportTemplate(e, t);
		return {
			html: n.html,
			mjml: n.mjml
		};
	}
	async function s(e) {
		let t = a();
		return (await i.exportTemplate(e, t)).mjml;
	}
	return {
		exportHtml: o,
		getMjmlSource: s
	};
}
function R(t) {
	let { authManager: n, onError: i } = t, a = e(null), o = e(!1), s = new g(n), c = r(() => a.value?.features ?? null);
	function l(e) {
		return a.value?.features[e] ?? !1;
	}
	async function u() {
		if (!o.value) {
			o.value = !0;
			try {
				a.value = await s.fetchConfig();
			} catch (e) {
				i?.(e instanceof Error ? e : Error("Failed to fetch config", { cause: e }));
			} finally {
				o.value = !1;
			}
		}
	}
	return {
		config: a,
		isLoading: o,
		hasFeature: l,
		features: c,
		fetchConfig: u
	};
}
var z = 5e3;
function B(e) {
	return e.authManager ? e.authManager.resolveUrl(h.health) : `${(e.baseUrl ?? "https://templatical.com").replace(/\/$/, "")}${h.health}`;
}
async function V(e, t) {
	let n = performance.now();
	try {
		let r = t ? await t.authenticatedFetch(h.health, {
			method: "GET",
			headers: { Accept: "application/json" }
		}) : await fetch(e, {
			method: "GET",
			headers: { Accept: "application/json" }
		}), i = Math.round(performance.now() - n);
		if (r.status === 401) return {
			api: {
				ok: !0,
				latency: i
			},
			auth: {
				ok: !1,
				error: "HTTP 401"
			}
		};
		if (!r.ok) return {
			api: {
				ok: !1,
				latency: i
			},
			auth: {
				ok: !t,
				error: t ? `HTTP ${r.status}` : void 0
			}
		};
		let a = await r.json();
		return {
			api: {
				ok: a.status === "ok",
				latency: i
			},
			auth: { ok: !0 },
			wsConfig: a.websocket
		};
	} catch (e) {
		return {
			api: {
				ok: !1,
				latency: Math.round(performance.now() - n)
			},
			auth: {
				ok: !t,
				error: t ? e instanceof Error ? e.message : "Authentication check failed" : void 0
			}
		};
	}
}
async function H(e) {
	if (!e?.host || !e?.app_key) return {
		ok: !1,
		error: "WebSocket configuration not available"
	};
	if (typeof WebSocket > "u") return {
		ok: !1,
		error: "WebSocket not supported in this environment"
	};
	let t = `${e.port === 443 ? "wss" : "ws"}://${e.host}:${e.port}/app/${e.app_key}?protocol=7&client=js&version=8.4.0-rc2&flash=false`;
	return new Promise((e) => {
		let n = setTimeout(() => {
			r.close(), e({
				ok: !1,
				error: "WebSocket connection timed out"
			});
		}, z), r = new WebSocket(t);
		r.onopen = () => {
			clearTimeout(n), r.close(), e({ ok: !0 });
		}, r.onerror = () => {
			clearTimeout(n), e({
				ok: !1,
				error: "WebSocket connection failed"
			});
		};
	});
}
async function U(e = {}) {
	let t = await V(B(e), e.authManager), n = await H(t.wsConfig);
	return {
		api: t.api,
		websocket: n,
		auth: t.auth,
		overall: t.api.ok && t.auth.ok
	};
}
function W(e) {
	let { editor: t, channel: n, onOperation: r } = e;
	i(n, (e, n) => {
		n && n.unbind("mcp-operation"), e && e.bind("mcp-operation", (e) => {
			y(t, e), r?.(e);
		});
	});
}
//#endregion
export { T as _, w as a, O as c, b as d, L as f, F as g, P as h, C as i, D as l, R as m, U as n, j as o, W as p, _ as r, M as s, s as t, E as u, I as v, N as y };
