import { H as e, M as t, P as n, V as r, Z as i, ct as a, f as o, g as s, h as c, it as l, m as u, o as d, ot as f, p, st as ee, u as m, v as h, x as g, y as _, z as v } from "./draggable-P6QWzy4g.js";
import { Ft as y, Zt as b, i as x, nn as S, qt as te, tt as ne, vt as C } from "./features-CgTy87Ni.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__ */ g({
	__name: "SaveModuleDialog",
	props: {
		visible: { type: Boolean },
		preSelectedBlockId: {}
	},
	emits: ["close", "saved"],
	setup(g, { emit: R }) {
		let z = g, B = R, { t: V } = y(), { t: H } = ne(), U = S(te, "SaveModuleDialog"), W = S(b, "SaveModuleDialog"), G = i(""), K = i(/* @__PURE__ */ new Set()), q = i(!1), J = i(null), Y = o(() => U.content.value.blocks);
		function X(e, t) {
			return `${V.blocks[e.type] ?? e.type} ${t + 1}`;
		}
		v(() => 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 = o(() => 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 (i, o) => (t(), u(x, {
			visible: g.visible,
			onClose: $,
			onKeydown: ae
		}, {
			default: r(() => [p("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)"
				}
			}, [
				p("h3", T, a(l(H).modules.saveAsModule), 1),
				p("div", E, [p("label", D, a(l(H).modules.moduleName), 1), e(p("input", {
					"onUpdate:modelValue": o[0] ||= (e) => G.value = e,
					type: "text",
					placeholder: l(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), [[d, G.value]])]),
				p("div", k, [p("label", A, a(l(H).modules.selectBlocks), 1), p("div", j, [(t(!0), s(m, null, n(Y.value, (e, n) => (t(), s("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: ee({
						color: "var(--tpl-text)",
						backgroundColor: K.value.has(e.id) ? "var(--tpl-primary-light)" : "transparent"
					})
				}, [p("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), h(" " + a(X(e, n)), 1)], 4))), 128))])]),
				J.value ? (t(), s("p", N, a(J.value), 1)) : c("", !0),
				p("div", P, [p("button", {
					type: "button",
					class: f(["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: $
				}, a(l(H).modules.cancel), 11, F), p("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 ? (t(), s("span", L, [_(l(C), {
					class: "tpl:animate-spin",
					size: 12,
					"stroke-width": 2
				}), h(" " + a(l(H).modules.saving), 1)])) : (t(), s("span", re, a(l(H).modules.save), 1))], 8, I)])
			], 8, w)]),
			_: 1
		}, 8, ["visible"]));
	}
});
//#endregion
export { R as default };

//# sourceMappingURL=SaveModuleDialog-D6szy5vX.js.map