import { A as e, B as t, E as n, L as r, M as i, X as a, _ as o, a as ee, at as te, b as s, f as c, h as l, l as u, m as d, p as f, rt as p, st as m, t as ne, v as h, w as re, z as ie } from "./vue.runtime.esm-bundler-BDSGA5hA.js";
import { o as ae, s as oe } from "./dist-HO0vjY5Z.js";
import { A as g, c as se, p as ce, r as _, v as le } from "./keys-B8K7Z7Ef.js";
import { t as v } from "./createLucideIcon-XgXOJ05E.js";
import { t as y } from "./circle-alert-CPH6l3Lc.js";
import { t as ue } from "./loader-circle-Rz_4vJLH.js";
import { t as de } from "./send-BhbhbIFT.js";
import { t as b } from "./sparkles-CrUN0KWY.js";
import { t as fe } from "./trash-2-BpY5BCLT.js";
import { t as pe } from "./x-rcnxRG8Y.js";
import { t as me } from "./LoadingTrack-xCOLUR3o.js";
import { t as x } from "./_plugin-vue_export-helper-B3ysoDQm.js";
import { t as S } from "./useAliveFlag-BLyG8L4d.js";
import { i as C } from "./cloud-Dz8Ay2FM.js";
var w = v("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 = v("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"
}]]), E = {
	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)]"
}, D = { class: "tpl:flex tpl:items-center tpl:justify-between tpl:border-b tpl:border-[var(--tpl-border)] tpl:px-4 tpl:py-3" }, O = { class: "tpl:flex tpl:items-center tpl:gap-1.5 tpl:text-sm tpl:font-medium tpl:text-[var(--tpl-primary)]" }, k = { class: "tpl:flex tpl:items-center tpl:gap-1" }, A = ["title"], j = { class: "tpl:relative tpl:flex tpl:min-h-0 tpl:flex-1 tpl:flex-col" }, M = {
	key: 0,
	class: "tpl:flex tpl:h-full tpl:flex-col tpl:items-center tpl:justify-center tpl:gap-3 tpl:text-center"
}, N = { class: "tpl:text-sm tpl:text-[var(--tpl-text-muted)]" }, P = {
	key: 1,
	class: "tpl:flex tpl:h-full tpl:flex-col tpl:items-center tpl:justify-center tpl:gap-3 tpl:text-center"
}, F = { class: "tpl:max-w-[240px] tpl:text-sm tpl:text-[var(--tpl-text-muted)]" }, I = {
	key: 2,
	class: "tpl:flex tpl:flex-col tpl:gap-4"
}, L = {
	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)"
	}
}, R = {
	key: 1,
	class: "tpl:flex tpl:flex-col tpl:gap-2"
}, z = {
	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)]" }, B = /* @__PURE__ */ x(/* @__PURE__ */ s({
	__name: "AiChatSidebar",
	props: {
		visible: { type: Boolean },
		onApply: { type: Function }
	},
	emits: ["close"],
	setup(s, { emit: v }) {
		let x = s, B = v, V = g(se, "AiChatSidebar"), H = g(ce, "AiChatSidebar"), we = g(_, "AiChatSidebar"), U = re(le, []), W = S(), G = C({
			authManager: we,
			getTemplateId: () => H.state.template?.id ?? null,
			onApply: x.onApply,
			onError: void 0
		}), K = a(""), q = a(null), J = a(!1), Y = a(0), { pause: X, resume: Te } = ae(() => {
			let e = G.suggestions.value?.length ?? 0;
			Y.value < e ? Y.value++ : X();
		}, 150, { immediate: !1 }), { start: Ee } = oe(() => Te(), 100, { immediate: !1 });
		r(() => G.suggestions.value?.length ?? 0, (e) => {
			if (X(), e === 0) {
				Y.value = 0;
				return;
			}
			Y.value = 0, Ee();
		});
		function Z() {
			n(() => {
				q.value && (q.value.scrollTop = q.value.scrollHeight);
			});
		}
		r(() => G.messages.value?.length ?? 0, () => Z()), r(() => x.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 (n, r) => (e(), f(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: ie(() => [s.visible ? (e(), l("div", E, [
				c("div", D, [c("div", O, [h(p(b), {
					size: 13,
					"stroke-width": 2
				}), c("span", null, m(p(V).aiChat.title), 1)]), c("div", k, [(p(G).messages.value?.length ?? 0) > 0 ? (e(), 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: p(V).aiChat.clear,
					onClick: r[0] ||= (e) => p(G).clearChat()
				}, [h(p(fe), {
					size: 14,
					"stroke-width": 2
				})], 8, A)) : d("", !0), c("button", {
					class: "tpl:rounded-md tpl:p-0.5 tpl:transition-colors tpl:duration-150 tpl:text-[var(--tpl-text-muted)]",
					onClick: r[1] ||= (e) => B("close")
				}, [h(p(pe), {
					size: 14,
					"stroke-width": 2
				})])])]),
				c("div", j, [
					c("div", {
						ref_key: "messagesContainer",
						ref: q,
						class: "tpl:flex-1 tpl:overflow-y-auto tpl:p-4"
					}, [p(G).isLoadingHistory.value ? (e(), l("div", M, [h(p(ue), {
						class: "tpl-spinner tpl:text-[var(--tpl-text-muted)]",
						size: 24,
						"stroke-width": 2
					}), c("p", N, m(p(V).aiChat.loadingHistory), 1)])) : (p(G).messages.value?.length ?? 0) === 0 ? (e(), l("div", P, [h(p(b), {
						size: 32,
						"stroke-width": 1.5,
						class: "tpl:text-[var(--tpl-text-dim)]"
					}), c("p", F, m(p(V).aiChat.placeholder), 1)])) : (e(), l("div", I, [(e(!0), l(u, null, i(p(G).messages.value, (t, n) => (e(), l("div", {
						key: t.id,
						class: "tpl:flex tpl:flex-col tpl:gap-2"
					}, [t.role === "user" ? (e(), l("div", L, m(t.content), 1)) : (e(), l("div", R, [!$(t.content) && p(G).isGenerating.value && n === (p(G).messages.value?.length ?? 0) - 1 ? (e(), f(me, { key: 0 })) : (e(), l("div", z, m($(t.content) || p(V).aiChat.applied), 1)), t.id === p(G).lastApplyMessageId.value && !p(G).isGenerating.value ? (e(), 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: r[2] ||= (e) => p(G).toggleLastRevert()
					}, [p(G).isLastChangeReverted.value ? (e(), l(u, { key: 0 }, [h(p(w), {
						size: 12,
						"stroke-width": 2
					}), o(" " + m(p(V).aiChat.reapply), 1)], 64)) : (e(), l(u, { key: 1 }, [h(p(T), {
						size: 12,
						"stroke-width": 2
					}), o(" " + m(p(V).aiChat.revert), 1)], 64))])) : d("", !0)]))]))), 128))]))], 512),
					p(G).error.value ? (e(), l("div", he, [h(p(y), {
						size: 14,
						"stroke-width": 2,
						class: "tpl:mt-0.5 tpl:shrink-0"
					}), c("span", null, m(p(G).error.value === "ai_apply_failed" ? p(V).aiChat.applyFailed : p(V).aiChat.error), 1)])) : d("", !0),
					(p(G).suggestions.value?.length ?? 0) > 0 ? (e(), l("div", ge, [c("div", _e, [(e(!0), l(u, null, i(p(G).suggestions.value ?? [], (t, n) => (e(), l("button", {
						key: n,
						class: te(["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", (p(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)
					}, m(t), 11, ve))), 128))])])) : d("", !0)
				]),
				c("div", ye, [c("div", be, [t(c("textarea", {
					"onUpdate:modelValue": r[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: p(V).aiChat.inputPlaceholder,
					disabled: p(G).isGenerating.value,
					rows: "3",
					onKeydown: Oe
				}, null, 40, xe), [[ee, K.value]]), c("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() || p(G).isGenerating.value,
					onClick: Q
				}, [h(p(de), {
					size: 16,
					"stroke-width": 2
				})], 8, Se)]), c("p", Ce, m(p(V).aiMenu.disclaimer), 1)])
			])) : d("", !0)]),
			_: 1
		}));
	}
}), [["__scopeId", "data-v-a55e4bff"]]);
//#endregion
export { B as default };
