import { A as e, B as t, L as n, M as r, X as i, _ as a, a as o, at as s, b as c, d as l, f as u, h as d, l as ee, m as f, ot as p, p as m, rt as h, st as g, v as _, z as v } from "./vue.runtime.esm-bundler-BDSGA5hA.js";
import "./useEditorCore-BXz-UXPd.js";
import { A as y, p as b, w as x } from "./keys-B8K7Z7Ef.js";
import { t as S } from "./useI18n-CBbStVlD.js";
import { t as te } from "./loader-circle-Rz_4vJLH.js";
import { n as ne } from "./useCloudI18n-DFzVgYhJ.js";
import { t as C } from "./TplModal-BEfwlvPC.js";
//#region src/cloud/components/SaveModuleDialog.vue?vue&type=script&setup=true&lang.ts
var w = ["aria-busy"], T = {
	id: "tpl-save-module-title",
	class: "tpl:mb-4 tpl:text-sm tpl:font-semibold tpl:text-[var(--tpl-text)]"
}, E = { class: "tpl:mb-3" }, D = { class: "tpl:mb-1.5 tpl:block tpl:text-sm tpl:font-medium tpl:text-[var(--tpl-text-muted)]" }, O = ["placeholder", "disabled"], k = { class: "tpl:mb-3" }, A = { class: "tpl:mb-1.5 tpl:block tpl:text-sm tpl:font-medium tpl:text-[var(--tpl-text-muted)]" }, j = { class: "tpl:max-h-40 tpl:space-y-1 tpl:overflow-y-auto tpl:rounded-md tpl:border tpl:p-2 tpl:border-[var(--tpl-border)]" }, M = [
	"checked",
	"disabled",
	"onChange"
], N = {
	key: 0,
	role: "alert",
	class: "tpl:mb-3 tpl:text-xs tpl:text-[var(--tpl-danger)]"
}, P = { class: "tpl:flex tpl:justify-end tpl:gap-2" }, F = ["disabled"], I = ["disabled"], L = {
	key: 0,
	class: "tpl:flex tpl:items-center tpl:gap-1.5"
}, re = { key: 1 }, R = /* @__PURE__ */ c({
	__name: "SaveModuleDialog",
	props: {
		visible: { type: Boolean },
		preSelectedBlockId: {}
	},
	emits: ["close", "saved"],
	setup(c, { emit: R }) {
		let z = c, B = R, { t: V } = S(), { t: H } = ne(), U = y(b, "SaveModuleDialog"), W = y(x, "SaveModuleDialog"), G = i(""), K = i(/* @__PURE__ */ new Set()), q = i(!1), J = i(null), Y = l(() => U.content.value.blocks);
		function X(e, t) {
			let n = e.type;
			return `${V.blocks[n] ?? e.type} ${t + 1}`;
		}
		n(() => z.visible, (e) => {
			e && (G.value = "", J.value = null, K.value = new Set(z.preSelectedBlockId ? [z.preSelectedBlockId] : []));
		});
		function ie(e) {
			let t = new Set(K.value);
			t.has(e) ? t.delete(e) : t.add(e), K.value = t;
		}
		let Z = l(() => G.value.trim().length > 0 && K.value.size > 0 && !q.value);
		async function Q() {
			if (Z.value) {
				q.value = !0, J.value = null;
				try {
					let e = Y.value.filter((e) => K.value.has(e.id));
					await W.createModule(G.value.trim(), e), B("saved"), B("close");
				} catch (e) {
					J.value = e.message;
				} finally {
					q.value = !1;
				}
			}
		}
		function $() {
			q.value || B("close");
		}
		function ae(e) {
			e.key === "Enter" && !e.shiftKey && (e.preventDefault(), Q()), e.key === "Escape" && $();
		}
		return (n, i) => (e(), m(C, {
			visible: c.visible,
			onClose: $,
			onKeydown: ae
		}, {
			default: v(() => [u("div", {
				role: "dialog",
				"aria-modal": "true",
				"aria-busy": q.value,
				"aria-labelledby": "tpl-save-module-title",
				class: "tpl-scale-in tpl:mx-4 tpl:w-full tpl:max-w-sm tpl:rounded-[var(--tpl-radius-lg)] tpl:p-5",
				style: {
					"background-color": "var(--tpl-bg-elevated)",
					"box-shadow": "var(--tpl-shadow-xl)"
				}
			}, [
				u("h3", T, g(h(H).modules.saveAsModule), 1),
				u("div", E, [u("label", D, g(h(H).modules.moduleName), 1), t(u("input", {
					"onUpdate:modelValue": i[0] ||= (e) => G.value = e,
					type: "text",
					placeholder: h(H).modules.moduleNamePlaceholder,
					class: "tpl:h-9 tpl:w-full tpl:rounded-md tpl:border tpl:px-3 tpl:py-1 tpl:text-sm tpl:shadow-xs tpl:outline-none tpl:border-[var(--tpl-border)] tpl:bg-[var(--tpl-bg)] tpl:text-[var(--tpl-text)]",
					disabled: q.value
				}, null, 8, O), [[o, G.value]])]),
				u("div", k, [u("label", A, g(h(H).modules.selectBlocks), 1), u("div", j, [(e(!0), d(ee, null, r(Y.value, (t, n) => (e(), d("label", {
					key: t.id,
					class: "tpl:flex tpl:cursor-pointer tpl:items-center tpl:gap-2 tpl:rounded-sm tpl:px-2 tpl:py-1.5 tpl:text-sm tpl:transition-colors tpl:duration-100",
					style: p({
						color: "var(--tpl-text)",
						backgroundColor: K.value.has(t.id) ? "var(--tpl-primary-light)" : "transparent"
					})
				}, [u("input", {
					type: "checkbox",
					checked: K.value.has(t.id),
					class: "tpl:accent-[var(--tpl-primary)]",
					disabled: q.value,
					onChange: (e) => ie(t.id)
				}, null, 40, M), a(" " + g(X(t, n)), 1)], 4))), 128))])]),
				J.value ? (e(), d("p", N, g(J.value), 1)) : f("", !0),
				u("div", P, [u("button", {
					type: "button",
					class: s(["tpl:cursor-pointer tpl:rounded-md tpl:border tpl:px-3 tpl:py-1.5 tpl:text-sm tpl:font-medium tpl:shadow-xs tpl:transition-all tpl:duration-150 tpl:border-[var(--tpl-border)] tpl:text-[var(--tpl-text)] tpl:bg-[var(--tpl-bg)]", { "tpl:cursor-not-allowed tpl:opacity-50": q.value }]),
					disabled: q.value,
					onClick: $
				}, g(h(H).modules.cancel), 11, F), u("button", {
					type: "button",
					class: "tpl:cursor-pointer tpl:rounded-md tpl:px-3 tpl:py-1.5 tpl:text-sm tpl:font-medium tpl:shadow-xs tpl:transition-all tpl:duration-150 tpl:hover:opacity-90 tpl:disabled:cursor-not-allowed tpl:disabled:opacity-50 tpl:bg-[var(--tpl-primary)] tpl:text-[var(--tpl-bg)]",
					disabled: !Z.value,
					onClick: Q
				}, [q.value ? (e(), d("span", L, [_(h(te), {
					class: "tpl:animate-spin",
					size: 12,
					"stroke-width": 2
				}), a(" " + g(h(H).modules.saving), 1)])) : (e(), d("span", re, g(h(H).modules.save), 1))], 8, I)])
			], 8, w)]),
			_: 1
		}, 8, ["visible"]));
	}
});
//#endregion
export { R as default };
