import { Dt as e, H as t, M as n, Mt as r, Ot as i, P as a, Q as o, S as s, V as c, _ as l, b as u, d, g as f, h as p, it as m, m as h, p as g, s as _, y as v, z as y } from "./vue.runtime.esm-bundler-DpvJL-nX.js";
import "./useEditorCore-D0uZbPKG.js";
import { D as b, S as x, p as S } from "./keys-BeW4IrXP.js";
import { t as ee } from "./useI18n-Jp3X6Q0t.js";
import { t as te } from "./loader-circle-IS16T05j.js";
import { n as ne } from "./useCloudI18n-D0Fi0hBU.js";
import { t as C } from "./TplModal-BiUCSfou.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__ */ s({
	__name: "SaveModuleDialog",
	props: {
		visible: { type: Boolean },
		preSelectedBlockId: {}
	},
	emits: ["close", "saved"],
	setup(s, { emit: R }) {
		let z = s, B = R, { t: V } = ee(), { t: H } = ne(), U = b(S, "SaveModuleDialog"), W = b(x, "SaveModuleDialog"), G = o(""), K = o(/* @__PURE__ */ new Set()), q = o(!1), J = o(null), Y = g(() => U.content.value.blocks);
		function X(e, t) {
			let n = e.type;
			return `${V.blocks[n] ?? e.type} ${t + 1}`;
		}
		y(() => 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 = g(() => 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 (o, g) => (n(), p(C, {
			visible: s.visible,
			onClose: $,
			onKeydown: ae
		}, {
			default: c(() => [h("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)"
				}
			}, [
				h("h3", T, r(m(H).modules.saveAsModule), 1),
				h("div", E, [h("label", D, r(m(H).modules.moduleName), 1), t(h("input", {
					"onUpdate:modelValue": g[0] ||= (e) => G.value = e,
					type: "text",
					placeholder: m(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), [[_, G.value]])]),
				h("div", k, [h("label", A, r(m(H).modules.selectBlocks), 1), h("div", j, [(n(!0), l(d, null, a(Y.value, (e, t) => (n(), l("label", {
					key: e.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: i({
						color: "var(--tpl-text)",
						backgroundColor: K.value.has(e.id) ? "var(--tpl-primary-light)" : "transparent"
					})
				}, [h("input", {
					type: "checkbox",
					checked: K.value.has(e.id),
					class: "tpl:accent-[var(--tpl-primary)]",
					disabled: q.value,
					onChange: (t) => ie(e.id)
				}, null, 40, M), v(" " + r(X(e, t)), 1)], 4))), 128))])]),
				J.value ? (n(), l("p", N, r(J.value), 1)) : f("", !0),
				h("div", P, [h("button", {
					type: "button",
					class: e(["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: $
				}, r(m(H).modules.cancel), 11, F), h("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 ? (n(), l("span", L, [u(m(te), {
					class: "tpl:animate-spin",
					size: 12,
					"stroke-width": 2
				}), v(" " + r(m(H).modules.saving), 1)])) : (n(), l("span", re, r(m(H).modules.save), 1))], 8, I)])
			], 8, w)]),
			_: 1
		}, 8, ["visible"]));
	}
});
//#endregion
export { R as default };
