import { Dt as e, E as t, H as n, M as r, Mt as i, O as a, P as o, Q as s, S as c, V as ee, _ as l, b as u, d, g as f, h as p, it as m, k as h, m as g, s as te, t as ne, y as _, z as v } from "./vue.runtime.esm-bundler-DpvJL-nX.js";
import { o as re, s as ie } from "./dist-CuyhAnuE.js";
import { D as y, _ as ae, c as oe, p as se, r as ce } from "./keys-BeW4IrXP.js";
import { n as b, t as x } from "./_plugin-vue_export-helper-GRmvIR5A.js";
import { t as le } from "./circle-alert-De74azaX.js";
import { t as ue } from "./loader-circle-IS16T05j.js";
import { t as de } from "./send-DRkFf4hP.js";
import { t as S } from "./sparkles-CD7TiNiC.js";
import { t as fe } from "./trash-2-cEVwp-r_.js";
import { t as pe } from "./x-BNc1bVzp.js";
import { t as me } from "./LoadingTrack-DhxulLPM.js";
import { i as C } from "./cloud-B1NAFg44.js";
var w = b("redo-2", [["path", {
	d: "m15 14 5-5-5-5",
	key: "12vg1m"
}], ["path", {
	d: "M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13",
	key: "6uklza"
}]]), T = b("undo-2", [["path", {
	d: "M9 14 4 9l5-5",
	key: "102s5s"
}], ["path", {
	d: "M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11",
	key: "f3b9sd"
}]]);
//#endregion
//#region src/composables/useAliveFlag.ts
function E() {
	let e = { alive: !0 };
	return h(() => {
		e.alive = !1;
	}), e;
}
//#endregion
//#region src/cloud/components/AiChatSidebar.vue?vue&type=script&setup=true&lang.ts
var D = {
	key: 0,
	class: "tpl-ai-sidebar tpl:absolute tpl:top-14 tpl:right-0 tpl:bottom-0 tpl:z-panel tpl:flex tpl:w-[360px] tpl:flex-col tpl:border-l tpl:border-[var(--tpl-border)] tpl:bg-[var(--tpl-bg-elevated)]"
}, O = { class: "tpl:flex tpl:items-center tpl:justify-between tpl:border-b tpl:border-[var(--tpl-border)] tpl:px-4 tpl:py-3" }, k = { class: "tpl:flex tpl:items-center tpl:gap-1.5 tpl:text-sm tpl:font-medium tpl:text-[var(--tpl-primary)]" }, A = { class: "tpl:flex tpl:items-center tpl:gap-1" }, j = ["title"], M = { class: "tpl:relative tpl:flex tpl:min-h-0 tpl:flex-1 tpl:flex-col" }, N = {
	key: 0,
	class: "tpl:flex tpl:h-full tpl:flex-col tpl:items-center tpl:justify-center tpl:gap-3 tpl:text-center"
}, P = { class: "tpl:text-sm tpl:text-[var(--tpl-text-muted)]" }, F = {
	key: 1,
	class: "tpl:flex tpl:h-full tpl:flex-col tpl:items-center tpl:justify-center tpl:gap-3 tpl:text-center"
}, I = { class: "tpl:max-w-[240px] tpl:text-sm tpl:text-[var(--tpl-text-muted)]" }, L = {
	key: 2,
	class: "tpl:flex tpl:flex-col tpl:gap-4"
}, R = {
	key: 0,
	class: "tpl:self-end tpl:rounded-[var(--tpl-radius-sm)] tpl:px-3.5 tpl:py-2.5 tpl:text-sm",
	style: {
		"background-color": "var(--tpl-primary-light)",
		color: "var(--tpl-text)",
		"max-width": "85%",
		"box-shadow": "var(--tpl-shadow)"
	}
}, z = {
	key: 1,
	class: "tpl:flex tpl:flex-col tpl:gap-2"
}, B = {
	key: 1,
	class: "tpl:rounded-[var(--tpl-radius-sm)] tpl:px-3.5 tpl:py-2.5 tpl:text-sm tpl:whitespace-pre-wrap",
	style: {
		"max-width": "85%",
		"background-color": "var(--tpl-bg)",
		color: "var(--tpl-text)",
		"box-shadow": "var(--tpl-shadow)"
	}
}, he = {
	key: 0,
	class: "tpl:mx-3 tpl:mb-2 tpl:flex tpl:items-start tpl:gap-2 tpl:rounded-lg tpl:px-3 tpl:py-2 tpl:text-xs",
	style: {
		"background-color": "var(--tpl-danger-light)",
		color: "var(--tpl-danger)"
	}
}, ge = {
	key: 1,
	class: "tpl:absolute tpl:right-0 tpl:bottom-0 tpl:left-0 tpl:z-10 tpl:px-3 tpl:pb-3",
	style: {
		"background-color": "color-mix(\n              in srgb,\n              var(--tpl-bg) 50%,\n              transparent\n            )",
		"backdrop-filter": "blur(2px)"
	}
}, _e = { class: "tpl:flex tpl:flex-col tpl:gap-1.5" }, ve = ["onClick"], ye = { class: "tpl:border-t tpl:p-3 tpl:border-[var(--tpl-border)]" }, be = { class: "tpl-ai-input-wrapper tpl:flex tpl:items-end tpl:gap-2 tpl:rounded-[var(--tpl-radius)] tpl:border tpl:px-3 tpl:py-2 tpl:border-[var(--tpl-border)] tpl:bg-[var(--tpl-bg)]" }, xe = ["placeholder", "disabled"], Se = ["disabled"], Ce = { class: "tpl:m-0 tpl:px-1 tpl:pt-2 tpl:text-center tpl:text-[11px] tpl:text-[var(--tpl-text-dim)]" }, V = /* @__PURE__ */ x(/* @__PURE__ */ c({
	__name: "AiChatSidebar",
	props: {
		visible: { type: Boolean },
		onApply: { type: Function }
	},
	emits: ["close"],
	setup(c, { emit: h }) {
		let b = c, x = h, V = y(oe, "AiChatSidebar"), H = y(se, "AiChatSidebar"), we = y(ce, "AiChatSidebar"), U = t(ae, []), W = E(), G = C({
			authManager: we,
			getTemplateId: () => H.state.template?.id ?? null,
			onApply: b.onApply,
			onError: void 0
		}), K = s(""), q = s(null), J = s(!1), Y = s(0), { pause: X, resume: Te } = re(() => {
			let e = G.suggestions.value?.length ?? 0;
			Y.value < e ? Y.value++ : X();
		}, 150, { immediate: !1 }), { start: Ee } = ie(() => Te(), 100, { immediate: !1 });
		v(() => G.suggestions.value?.length ?? 0, (e) => {
			if (X(), e === 0) {
				Y.value = 0;
				return;
			}
			Y.value = 0, Ee();
		});
		function Z() {
			a(() => {
				q.value && (q.value.scrollTop = q.value.scrollHeight);
			});
		}
		v(() => G.messages.value?.length ?? 0, () => Z()), v(() => b.visible, async (e) => {
			if (e && !J.value) {
				if (J.value = !0, await G.loadConversation(), !W.alive) return;
				(G.messages.value?.length ?? 0) === 0 && H.content.value.blocks.length === 0 && G.loadSuggestions(H.content.value, U);
			}
		});
		async function Q() {
			let e = K.value.trim();
			!e || G.isGenerating.value || (K.value = "", G.error.value = null, G.failedPrompt.value = null, Z(), await G.sendPrompt(e, H.content.value, U), W.alive && (G.failedPrompt.value && (K.value = G.failedPrompt.value), Z()));
		}
		function $(e) {
			return e.replace(/```json[\s\S]*?```/g, "").replace(/```json[\s\S]*/g, "").trim();
		}
		function De(e) {
			X(), K.value = e, Q();
		}
		function Oe(e) {
			e.key === "Enter" && !e.shiftKey && (e.preventDefault(), Q());
		}
		return (t, a) => (r(), p(ne, {
			"enter-active-class": "tpl-ai-slide-enter-active",
			"enter-from-class": "tpl:translate-x-full",
			"enter-to-class": "tpl:translate-x-0",
			"leave-active-class": "tpl-ai-slide-leave-active",
			"leave-from-class": "tpl:translate-x-0",
			"leave-to-class": "tpl:translate-x-full"
		}, {
			default: ee(() => [c.visible ? (r(), l("div", D, [
				g("div", O, [g("div", k, [u(m(S), {
					size: 13,
					"stroke-width": 2
				}), g("span", null, i(m(V).aiChat.title), 1)]), g("div", A, [(m(G).messages.value?.length ?? 0) > 0 ? (r(), l("button", {
					key: 0,
					class: "tpl:rounded-md tpl:p-0.5 tpl:transition-colors tpl:duration-150 tpl:text-[var(--tpl-text-muted)]",
					title: m(V).aiChat.clear,
					onClick: a[0] ||= (e) => m(G).clearChat()
				}, [u(m(fe), {
					size: 14,
					"stroke-width": 2
				})], 8, j)) : f("", !0), g("button", {
					class: "tpl:rounded-md tpl:p-0.5 tpl:transition-colors tpl:duration-150 tpl:text-[var(--tpl-text-muted)]",
					onClick: a[1] ||= (e) => x("close")
				}, [u(m(pe), {
					size: 14,
					"stroke-width": 2
				})])])]),
				g("div", M, [
					g("div", {
						ref_key: "messagesContainer",
						ref: q,
						class: "tpl:flex-1 tpl:overflow-y-auto tpl:p-4"
					}, [m(G).isLoadingHistory.value ? (r(), l("div", N, [u(m(ue), {
						class: "tpl-spinner tpl:text-[var(--tpl-text-muted)]",
						size: 24,
						"stroke-width": 2
					}), g("p", P, i(m(V).aiChat.loadingHistory), 1)])) : (m(G).messages.value?.length ?? 0) === 0 ? (r(), l("div", F, [u(m(S), {
						size: 32,
						"stroke-width": 1.5,
						class: "tpl:text-[var(--tpl-text-dim)]"
					}), g("p", I, i(m(V).aiChat.placeholder), 1)])) : (r(), l("div", L, [(r(!0), l(d, null, o(m(G).messages.value, (e, t) => (r(), l("div", {
						key: e.id,
						class: "tpl:flex tpl:flex-col tpl:gap-2"
					}, [e.role === "user" ? (r(), l("div", R, i(e.content), 1)) : (r(), l("div", z, [!$(e.content) && m(G).isGenerating.value && t === (m(G).messages.value?.length ?? 0) - 1 ? (r(), p(me, { key: 0 })) : (r(), l("div", B, i($(e.content) || m(V).aiChat.applied), 1)), e.id === m(G).lastApplyMessageId.value && !m(G).isGenerating.value ? (r(), l("button", {
						key: 2,
						class: "tpl:inline-flex tpl:items-center tpl:gap-1.5 tpl:self-start tpl:rounded-md tpl:border tpl:px-2.5 tpl:py-1.5 tpl:text-xs tpl:font-medium tpl:transition-all tpl:duration-150",
						style: {
							"border-color": "var(--tpl-border)",
							color: "var(--tpl-text-muted)",
							"background-color": "transparent"
						},
						onClick: a[2] ||= (e) => m(G).toggleLastRevert()
					}, [m(G).isLastChangeReverted.value ? (r(), l(d, { key: 0 }, [u(m(w), {
						size: 12,
						"stroke-width": 2
					}), _(" " + i(m(V).aiChat.reapply), 1)], 64)) : (r(), l(d, { key: 1 }, [u(m(T), {
						size: 12,
						"stroke-width": 2
					}), _(" " + i(m(V).aiChat.revert), 1)], 64))])) : f("", !0)]))]))), 128))]))], 512),
					m(G).error.value ? (r(), l("div", he, [u(m(le), {
						size: 14,
						"stroke-width": 2,
						class: "tpl:mt-0.5 tpl:shrink-0"
					}), g("span", null, i(m(G).error.value === "ai_apply_failed" ? m(V).aiChat.applyFailed : m(V).aiChat.error), 1)])) : f("", !0),
					(m(G).suggestions.value?.length ?? 0) > 0 ? (r(), l("div", ge, [g("div", _e, [(r(!0), l(d, null, o(m(G).suggestions.value ?? [], (t, n) => (r(), l("button", {
						key: n,
						class: e(["tpl-suggestion-btn tpl:cursor-pointer tpl:rounded-[var(--tpl-radius-sm)] tpl:border tpl:px-3 tpl:py-2 tpl:text-left tpl:text-xs tpl:leading-snug tpl:transition-all tpl:duration-300 tpl:ease-out", (m(G).suggestions.value?.length ?? 0) - 1 - n < Y.value ? "tpl:translate-y-0 tpl:opacity-100" : "tpl:pointer-events-none tpl:-translate-y-2 tpl:opacity-0"]),
						style: {
							"border-color": "var(--tpl-border)",
							color: "var(--tpl-primary)",
							"background-color": "var(--tpl-bg)",
							"box-shadow": "var(--tpl-shadow)"
						},
						onClick: (e) => De(t)
					}, i(t), 11, ve))), 128))])])) : f("", !0)
				]),
				g("div", ye, [g("div", be, [n(g("textarea", {
					"onUpdate:modelValue": a[3] ||= (e) => K.value = e,
					class: "tpl:max-h-32 tpl:min-h-[64px] tpl:flex-1 tpl:resize-none tpl:border-none tpl:bg-transparent tpl:font-sans tpl:text-sm tpl:outline-none tpl:text-[var(--tpl-text)]",
					placeholder: m(V).aiChat.inputPlaceholder,
					disabled: m(G).isGenerating.value,
					rows: "3",
					onKeydown: Oe
				}, null, 40, xe), [[te, K.value]]), g("button", {
					class: "tpl-ai-send-btn tpl:flex tpl:shrink-0 tpl:items-center tpl:justify-center tpl:rounded-md tpl:p-1.5 tpl:transition-all tpl:duration-150 tpl:disabled:opacity-40 tpl:text-[var(--tpl-primary)]",
					disabled: !K.value.trim() || m(G).isGenerating.value,
					onClick: Q
				}, [u(m(de), {
					size: 16,
					"stroke-width": 2
				})], 8, Se)]), g("p", Ce, i(m(V).aiMenu.disclaimer), 1)])
			])) : f("", !0)]),
			_: 1
		}));
	}
}), [["__scopeId", "data-v-a55e4bff"]]);
//#endregion
export { V as default };
