const require_rolldown_runtime = require("./rolldown-runtime-Dp2H1eGw.cjs");
require("./jszip-DCT9QYaK.cjs");
const require_vue = require("./vue-C-HNW35X.cjs");
const require__plugin_vue_export_helper = require("./_plugin-vue_export-helper-8HvmX3k_.cjs");
var _hoisted_1 = ["onKeydown"];
var _hoisted_2 = ["id"];
var _hoisted_3 = { class: "sd-password-prompt__description" };
var _hoisted_4 = { class: "sd-password-prompt__field" };
var _hoisted_5 = [
	"placeholder",
	"disabled",
	"aria-label"
];
var _hoisted_6 = {
	key: 0,
	class: "sd-password-prompt__error",
	role: "alert"
};
var _hoisted_7 = { class: "sd-password-prompt__actions" };
var _hoisted_8 = ["disabled"];
var _hoisted_9 = ["disabled"];
var _sfc_main = {
	__name: "PasswordPromptSurface",
	props: {
		surfaceId: {
			type: String,
			default: ""
		},
		mode: {
			type: String,
			default: "dialog"
		},
		request: {
			type: Object,
			default: () => ({})
		},
		resolve: {
			type: Function,
			default: () => {}
		},
		close: {
			type: Function,
			default: () => {}
		},
		passwordPrompt: {
			type: Object,
			required: true
		}
	},
	setup(__props) {
		const props = __props;
		const password = require_vue.ref("");
		const isBusy = require_vue.ref(false);
		const isInvalid = require_vue.ref(props.passwordPrompt.errorCode === "DOCX_PASSWORD_INVALID");
		const errorMessage = require_vue.ref(isInvalid.value ? props.passwordPrompt.texts.invalidMessage : "");
		const heading = require_vue.computed(() => isInvalid.value ? props.passwordPrompt.texts.invalidTitle : props.passwordPrompt.texts.title);
		const canSubmit = require_vue.computed(() => password.value.length > 0 && !isBusy.value);
		async function handleSubmit() {
			if (!canSubmit.value) return;
			isBusy.value = true;
			errorMessage.value = "";
			const result = await props.passwordPrompt.attemptPassword(password.value);
			if (result.success) {
				props.resolve({ password: password.value });
				return;
			}
			isBusy.value = false;
			password.value = "";
			if (result.errorCode === "DOCX_PASSWORD_INVALID") {
				isInvalid.value = true;
				errorMessage.value = props.passwordPrompt.texts.invalidMessage;
			} else if (result.errorCode === "timeout") errorMessage.value = props.passwordPrompt.texts.timeoutMessage;
			else errorMessage.value = props.passwordPrompt.texts.genericErrorMessage;
		}
		function handleCancel() {
			props.close("user-cancelled");
		}
		return (_ctx, _cache) => {
			return require_vue.openBlock(), require_vue.createElementBlock("div", {
				class: "sd-password-prompt",
				onKeydown: require_vue.withKeys(require_vue.withModifiers(handleSubmit, ["prevent"]), ["enter"])
			}, [
				require_vue.createBaseVNode("h3", {
					id: `sd-password-prompt-heading-${__props.surfaceId}`,
					class: "sd-password-prompt__heading"
				}, require_vue.toDisplayString(heading.value), 9, _hoisted_2),
				require_vue.createBaseVNode("p", _hoisted_3, require_vue.toDisplayString(__props.passwordPrompt.texts.description), 1),
				require_vue.createBaseVNode("div", _hoisted_4, [require_vue.withDirectives(require_vue.createBaseVNode("input", {
					"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => password.value = $event),
					type: "password",
					class: "sd-password-prompt__input",
					placeholder: __props.passwordPrompt.texts.placeholder,
					disabled: isBusy.value,
					autocomplete: "current-password",
					"aria-label": __props.passwordPrompt.texts.inputAriaLabel
				}, null, 8, _hoisted_5), [[require_vue.vModelText, password.value]])]),
				errorMessage.value ? (require_vue.openBlock(), require_vue.createElementBlock("p", _hoisted_6, require_vue.toDisplayString(errorMessage.value), 1)) : require_vue.createCommentVNode("", true),
				require_vue.createBaseVNode("div", _hoisted_7, [require_vue.createBaseVNode("button", {
					type: "button",
					class: "sd-password-prompt__btn sd-password-prompt__btn--cancel",
					disabled: isBusy.value,
					onClick: handleCancel
				}, require_vue.toDisplayString(__props.passwordPrompt.texts.cancelLabel), 9, _hoisted_8), require_vue.createBaseVNode("button", {
					type: "button",
					class: "sd-password-prompt__btn sd-password-prompt__btn--submit",
					disabled: !canSubmit.value,
					onClick: handleSubmit
				}, require_vue.toDisplayString(isBusy.value ? __props.passwordPrompt.texts.busyLabel : __props.passwordPrompt.texts.submitLabel), 9, _hoisted_9)])
			], 40, _hoisted_1);
		};
	}
};
var PasswordPromptSurface_default = /* @__PURE__ */ require__plugin_vue_export_helper.__plugin_vue_export_helper_default(_sfc_main, [["__scopeId", "data-v-ecf7f6fb"]]);
exports.default = PasswordPromptSurface_default;
