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

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