import { n as useTranslation, t as Trans } from "./i18n-DoP1NB7u.js";
import { _ as y, h as q, l as A, v as u } from "./vendor-preact-DThS2ZQ_.js";
import { c as useManager, o as useModuleTerminalCallbacks } from "./hooks-Da_yP_Dr.js";
import { t as IncodeComponent } from "./incodeComponent-CCP7GTMj.js";
import { t as Page } from "./page-DidH_RkX.js";
import { t as Button } from "./button-BMYTQ8fc.js";
import { c as ChevronLeftIcon, r as LockIcon } from "./icons-CJJbIpBq.js";
import { t as SuccessIcon } from "./successIcon-B5mGvdx1.js";
import { t as AutoFocusTitle } from "./autoFocusTitle-CuRu2lPg.js";
import { t as VerificationResult } from "./verificationResult-Brj8WSyW.js";
import { t as Checkbox } from "./checkbox-1wUHSoaK.js";
import { t as PdfViewer } from "./pdfViewer-D2gNFPfI.js";
import { t as registerIncodeModuleElement } from "./incodeModule-M8DszCee.js";
import { createElectronicSignatureManager } from "@incodetech/core/electronic-signature";
//#region src/modules/electronic-signature/documentIllustration.tsx
var DocumentIllustration = () => /* @__PURE__ */ u("svg", {
	xmlns: "http://www.w3.org/2000/svg",
	width: "233",
	height: "289",
	viewBox: "0 0 233 289",
	fill: "none",
	"aria-hidden": "true",
	children: [
		/* @__PURE__ */ u("g", {
			filter: "url(#aes-doc-shadow)",
			children: [/* @__PURE__ */ u("path", {
				d: "M24 26C24 23.2386 26.2386 21 29 21H203.757C206.518 21 208.757 23.2386 208.757 26V256.421C208.757 259.182 206.518 261.421 203.757 261.421H29C26.2386 261.421 24 259.182 24 256.421V26Z",
				fill: "white"
			}), /* @__PURE__ */ u("path", {
				d: "M24 26C24 23.2386 26.2386 21 29 21H203.757C206.518 21 208.757 23.2386 208.757 26V256.421C208.757 259.182 206.518 261.421 203.757 261.421H29C26.2386 261.421 24 259.182 24 256.421V26Z",
				fill: "black",
				"fill-opacity": "0.01"
			})]
		}),
		/* @__PURE__ */ u("g", {
			opacity: "0.5",
			children: [
				/* @__PURE__ */ u("path", {
					"fill-rule": "evenodd",
					"clip-rule": "evenodd",
					d: "M39.7534 55.606C39.7534 55.1047 40.1599 54.6982 40.6613 54.6982H192.611C193.113 54.6982 193.519 55.1047 193.519 55.606V58.4219C193.519 58.9233 193.113 59.3297 192.611 59.3297H40.6613C40.1599 59.3297 39.7534 58.9233 39.7534 58.4219V55.606Z",
					fill: "#C6C8D2"
				}),
				/* @__PURE__ */ u("path", {
					"fill-rule": "evenodd",
					"clip-rule": "evenodd",
					d: "M39.7534 226.972C39.7534 226.47 40.1599 226.064 40.6613 226.064H192.611C193.113 226.064 193.519 226.47 193.519 226.972V229.788C193.519 230.289 193.113 230.695 192.611 230.695H40.6613C40.1599 230.695 39.7534 230.289 39.7534 229.788V226.972Z",
					fill: "#C6C8D2"
				}),
				/* @__PURE__ */ u("path", {
					d: "M39.7534 80.6165C39.7534 80.1152 40.1599 79.7087 40.6613 79.7087H100.908C101.409 79.7087 101.816 80.1152 101.816 80.6165V88.9902C101.816 89.4916 101.409 89.898 100.908 89.898H40.6613C40.1599 89.898 39.7534 89.4916 39.7534 88.9902L39.7534 80.6165Z",
					fill: "#C6C8D2"
				}),
				/* @__PURE__ */ u("path", {
					d: "M39.7534 100.069C39.7534 99.5676 40.1598 99.1612 40.6612 99.1612H100.908C101.409 99.1612 101.815 99.5676 101.815 100.069V108.443C101.815 108.944 101.409 109.35 100.908 109.35H40.6612C40.1598 109.35 39.7534 108.944 39.7534 108.443L39.7534 100.069Z",
					fill: "#C6C8D2"
				}),
				/* @__PURE__ */ u("path", {
					d: "M39.7376 119.521C39.7463 119.019 40.1598 118.62 40.6611 118.629L125.905 120.117C126.406 120.125 126.805 120.539 126.796 121.04L126.65 129.413C126.642 129.914 126.228 130.313 125.727 130.304L40.4833 128.817C39.982 128.808 39.5827 128.394 39.5914 127.893L39.7376 119.521Z",
					fill: "#C6C8D2"
				}),
				/* @__PURE__ */ u("path", {
					d: "M39.7376 138.973C39.7463 138.472 40.1598 138.072 40.6611 138.081L65.7043 138.518C66.2056 138.527 66.6049 138.941 66.5962 139.442L66.4824 145.962C66.4736 146.463 66.0602 146.862 65.5589 146.854L40.5156 146.417C40.0143 146.408 39.615 145.994 39.6238 145.493L39.7376 138.973Z",
					fill: "#C6C8D2"
				}),
				/* @__PURE__ */ u("path", {
					d: "M39.7534 32.4487C39.7534 31.9473 40.1599 31.5409 40.6613 31.5409H153.707C154.208 31.5409 154.615 31.9473 154.615 32.4487V41.7487C154.615 42.25 154.208 42.6565 153.707 42.6565H40.6613C40.1599 42.6565 39.7534 42.25 39.7534 41.7487V32.4487Z",
					fill: "#C6C8D2"
				}),
				/* @__PURE__ */ u("path", {
					d: "M170.362 31.5221C170.362 31.0208 170.768 30.6143 171.27 30.6143H192.611C193.113 30.6143 193.519 31.0208 193.519 31.5221V40.8221C193.519 41.3235 193.113 41.7299 192.611 41.7299H171.27C170.768 41.7299 170.362 41.3235 170.362 40.8221V31.5221Z",
					fill: "#C6C8D2"
				})
			]
		}),
		/* @__PURE__ */ u("defs", { children: /* @__PURE__ */ u("filter", {
			id: "aes-doc-shadow",
			x: "0",
			y: "0",
			width: "232.757",
			height: "288.421",
			filterUnits: "userSpaceOnUse",
			"color-interpolation-filters": "sRGB",
			children: [
				/* @__PURE__ */ u("feFlood", {
					"flood-opacity": "0",
					result: "BackgroundImageFix"
				}),
				/* @__PURE__ */ u("feColorMatrix", {
					in: "SourceAlpha",
					type: "matrix",
					values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 127 0",
					result: "hardAlpha"
				}),
				/* @__PURE__ */ u("feOffset", { dy: "3" }),
				/* @__PURE__ */ u("feGaussianBlur", { stdDeviation: "12" }),
				/* @__PURE__ */ u("feComposite", {
					in2: "hardAlpha",
					operator: "out"
				}),
				/* @__PURE__ */ u("feColorMatrix", {
					type: "matrix",
					values: "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.08 0"
				}),
				/* @__PURE__ */ u("feBlend", {
					mode: "normal",
					in2: "BackgroundImageFix",
					result: "effect1_dropShadow"
				}),
				/* @__PURE__ */ u("feBlend", {
					mode: "normal",
					in: "SourceGraphic",
					in2: "effect1_dropShadow",
					result: "shape"
				})
			]
		}) })
	]
});
//#endregion
//#region src/modules/electronic-signature/consentItems.tsx
function AeTerms1Label() {
	return /* @__PURE__ */ u("span", { children: /* @__PURE__ */ u(Trans, {
		i18nKey: "aes.confirmSignature.terms1.title",
		components: { 2: /* @__PURE__ */ u("a", {
			href: "https://psc.incode.com/repositorio/",
			target: "_blank",
			rel: "noopener noreferrer"
		}) }
	}) });
}
function getAeConsentItems(t) {
	return [
		{
			id: "terms",
			label: /* @__PURE__ */ u(AeTerms1Label, {})
		},
		{
			id: "signElectronically",
			label: t("aes.confirmSignature.terms2.title")
		},
		{
			id: "signDisplayed",
			label: t("aes.confirmSignature.terms3.title")
		}
	];
}
function TermsAgreementLabel() {
	return /* @__PURE__ */ u("span", { children: /* @__PURE__ */ u(Trans, {
		i18nKey: "qes.newTermsCheck",
		components: {
			2: /* @__PURE__ */ u("a", {
				href: "https://policies.incodesmile.com/terms-of-use/",
				target: "_blank",
				rel: "noopener noreferrer"
			}),
			6: /* @__PURE__ */ u("a", {
				href: "https://policies.incodesmile.com/privacy-policy/",
				target: "_blank",
				rel: "noopener noreferrer"
			})
		}
	}) });
}
function getQeConsentItems(t) {
	return [
		{
			id: "issuance",
			label: t("qes.issuanceCheck")
		},
		{
			id: "qesAcknowledgement",
			label: t("qes.qesAcknowledgementCheck")
		},
		{
			id: "qscdConfirmation",
			label: t("qes.qscdConfirmationCheck")
		},
		{
			id: "termsAgreement",
			label: /* @__PURE__ */ u(TermsAgreementLabel, {})
		},
		{
			id: "documentsReviewed",
			label: t("qes.documentsReviewedCheck")
		}
	];
}
function getConsentItems(variant, t) {
	return variant === "qe" ? getQeConsentItems(t) : getAeConsentItems(t);
}
function getVariantCopy(variant, t) {
	if (variant === "qe") return {
		signingTitle: t("qes.consent.title"),
		signingSubtitle: t("qes.consent.text"),
		signButtonLabel: t("forms.button.continue")
	};
	return {
		signingTitle: t("aes.confirmSignature.title"),
		signingSubtitle: t("aes.confirmSignature.subtitle"),
		signButtonLabel: t("aes.confirmSignature.finishSigning")
	};
}
//#endregion
//#region src/modules/electronic-signature/electronic-signature.tsx
var ElectronicSignatureContent = ({ config, onFinish, onError }) => {
	const { t } = useTranslation();
	const [state, manager] = useManager(() => createElectronicSignatureManager({ config }));
	const fileInputRef = A(null);
	y(() => {
		manager.load();
	}, [manager]);
	useModuleTerminalCallbacks({
		status: state.status,
		onFinish,
		onError: state.status === "closed" ? () => onError?.("closed") : onError,
		error: state.status === "failed" ? state.errorMessage : void 0,
		errorStatuses: ["failed"]
	});
	const handleFileChange = q((event) => {
		const file = event.target.files?.[0];
		if (!file) return;
		const reader = new FileReader();
		reader.onload = () => {
			if (reader.result instanceof ArrayBuffer) {
				const fileUrl = URL.createObjectURL(new Blob([reader.result], { type: "application/pdf" }));
				manager.selectFile(file.name, reader.result, fileUrl);
			}
		};
		reader.readAsArrayBuffer(file);
	}, [manager]);
	const triggerFileInput = q(() => {
		fileInputRef.current?.click();
	}, []);
	if (state.status === "loading") return /* @__PURE__ */ u(VerificationResult, {
		status: "submitting",
		submittingTitle: t("common.processing")
	});
	if (state.status === "uploading") return /* @__PURE__ */ u(Page, {
		className: "IncodeElectronicSignature",
		title: t("aes.confirmSignature.uploadTitle"),
		subtitle: t("aes.confirmSignature.uploadDescription"),
		children: [/* @__PURE__ */ u("div", {
			className: "IncodeElectronicSignatureUploadBody",
			children: [/* @__PURE__ */ u("div", {
				className: "IncodeElectronicSignatureIllustration",
				children: /* @__PURE__ */ u(DocumentIllustration, {})
			}), /* @__PURE__ */ u("input", {
				ref: fileInputRef,
				type: "file",
				accept: "application/pdf",
				className: "IncodeElectronicSignatureFileInput",
				onChange: handleFileChange,
				tabIndex: -1,
				"aria-hidden": "true"
			})]
		}), /* @__PURE__ */ u("div", {
			className: "IncodeElectronicSignatureFooter",
			children: /* @__PURE__ */ u(Button, {
				onClick: triggerFileInput,
				children: t("aes.confirmSignature.addDocument")
			})
		})]
	});
	if (state.status === "reviewing") return /* @__PURE__ */ u(ReviewScreen, {
		state,
		manager,
		t
	});
	if (state.status === "processing") return /* @__PURE__ */ u(VerificationResult, {
		status: "submitting",
		submittingTitle: t("common.processing")
	});
	if (state.status === "success") {
		if (state.downloadDocument) return /* @__PURE__ */ u(Page, {
			className: "IncodeElectronicSignature IncodeElectronicSignatureSuccess",
			children: [/* @__PURE__ */ u("div", {
				className: "IncodeElectronicSignatureSuccessCenter",
				children: [/* @__PURE__ */ u(SuccessIcon, { size: 64 }), /* @__PURE__ */ u(AutoFocusTitle, {
					className: "IncodeElectronicSignatureSuccessTitle",
					children: t("signature.successTitle")
				})]
			}), /* @__PURE__ */ u("div", {
				className: "IncodeElectronicSignatureFooter",
				children: [/* @__PURE__ */ u(Button, {
					onClick: () => manager.finish(),
					children: t("common.continue")
				}), state.signedDocuments.map((doc, i) => /* @__PURE__ */ u("a", {
					href: doc.signedDocumentUrl,
					target: "_blank",
					rel: "noopener noreferrer",
					className: "IncodeElectronicSignatureDownloadLink",
					children: t("aes.confirmSignature.downloadDocument")
				}, i))]
			})]
		});
		return /* @__PURE__ */ u(VerificationResult, {
			status: "success",
			successTitle: t("signature.successTitle")
		});
	}
	if (state.status === "error") return /* @__PURE__ */ u(VerificationResult, {
		status: "warning",
		warningTitle: t("aes.confirmSignature.fail"),
		onRetry: () => manager.retry()
	});
	if (state.status === "signing") {
		if (state.viewingDocumentUrl) return /* @__PURE__ */ u(Page, {
			className: "IncodeElectronicSignature",
			children: [/* @__PURE__ */ u("div", {
				className: "IncodeElectronicSignatureDocViewHeader",
				children: /* @__PURE__ */ u(Button, {
					size: "M",
					variant: "link",
					class: "IncodeElectronicSignatureBackButton",
					icon: /* @__PURE__ */ u(ChevronLeftIcon, { variant: "m" }),
					onClick: () => manager.closeDocumentView(),
					"aria-label": t("common.back")
				})
			}), /* @__PURE__ */ u(PdfViewer, {
				url: state.viewingDocumentUrl,
				mode: "full",
				className: "IncodeElectronicSignatureDocViewer",
				"aria-label": t("aes.confirmSignature.viewDocument")
			})]
		});
		const variant = state.variant;
		const consentItems = getConsentItems(variant, t);
		const copy = getVariantCopy(variant, t);
		return /* @__PURE__ */ u(Page, {
			className: "IncodeElectronicSignature",
			title: copy.signingTitle,
			subtitle: copy.signingSubtitle,
			children: [/* @__PURE__ */ u("div", {
				className: "IncodeElectronicSignatureSigningTop",
				children: /* @__PURE__ */ u("div", {
					className: "IncodeElectronicSignatureDocContainer",
					children: state.documents.map((doc, i) => /* @__PURE__ */ u("div", {
						className: "IncodeElectronicSignatureDocRow",
						children: [/* @__PURE__ */ u("span", {
							className: "IncodeElectronicSignatureDocRowName",
							children: [
								t("aes.confirmSignature.contract"),
								i === 0 ? "" : `${i + 1}`,
								".pdf"
							]
						}), /* @__PURE__ */ u(Button, {
							variant: "link",
							size: "S",
							class: "IncodeElectronicSignatureDocRowAction",
							onClick: () => manager.viewDocument(doc.documentUrl),
							children: t("aes.confirmSignature.viewDocument")
						})]
					}, doc.documentRef))
				})
			}), /* @__PURE__ */ u("div", {
				className: "IncodeElectronicSignatureSigningBottom",
				children: [/* @__PURE__ */ u("div", {
					className: "IncodeElectronicSignatureConsents",
					children: consentItems.map((item) => /* @__PURE__ */ u(Checkbox, {
						id: `es-${item.id}`,
						label: item.label,
						size: "s",
						checked: !!state.consentChecks[item.id],
						onChange: () => manager.setConsent(item.id, !state.consentChecks[item.id])
					}, item.id))
				}), /* @__PURE__ */ u("div", {
					className: "IncodeElectronicSignatureFooter",
					children: /* @__PURE__ */ u(Button, {
						onClick: () => manager.sign(),
						disabled: !state.allConsented,
						children: copy.signButtonLabel
					})
				})]
			})]
		});
	}
	return null;
};
var ReviewScreen = ({ state, manager, t }) => {
	y(() => () => URL.revokeObjectURL(state.fileUrl), [state.fileUrl]);
	return /* @__PURE__ */ u(Page, {
		className: "IncodeElectronicSignature",
		title: t("aes.reviewDocument.title"),
		subtitle: t("aes.reviewDocument.subtitle"),
		children: [/* @__PURE__ */ u("div", {
			className: "IncodeElectronicSignatureReviewBody",
			children: [/* @__PURE__ */ u("div", {
				className: "IncodeElectronicSignatureReviewCard",
				children: [/* @__PURE__ */ u("div", {
					className: "IncodeElectronicSignatureDocPreview",
					children: /* @__PURE__ */ u(PdfViewer, {
						url: state.fileUrl,
						mode: "thumbnail",
						className: "IncodeElectronicSignatureDocPreviewObject",
						"aria-label": state.fileName
					})
				}), /* @__PURE__ */ u("p", {
					className: "IncodeElectronicSignatureDocName",
					children: state.fileName
				})]
			}), /* @__PURE__ */ u("div", {
				className: "IncodeElectronicSignatureEncrypted",
				children: [/* @__PURE__ */ u(LockIcon, { className: "IncodeElectronicSignatureEncryptedIcon" }), /* @__PURE__ */ u("span", { children: t("encryptionLabel.encryptedPhotos") })]
			})]
		}), /* @__PURE__ */ u("div", {
			className: "IncodeElectronicSignatureFooter",
			children: [/* @__PURE__ */ u(Button, {
				onClick: () => manager.confirmFile(),
				children: t("common.continue")
			}), /* @__PURE__ */ u(Button, {
				variant: "secondary",
				onClick: () => manager.replaceFile(),
				children: t("aes.reviewDocument.replace")
			})]
		})]
	});
};
var ElectronicSignature = ({ config, onFinish, onError }) => {
	return /* @__PURE__ */ u(IncodeComponent, { children: config ? /* @__PURE__ */ u(ElectronicSignatureContent, {
		config,
		onFinish,
		onError
	}) : null });
};
/** @deprecated Use {@link ElectronicSignature} */
var AeSignature = ElectronicSignature;
registerIncodeModuleElement(ElectronicSignature, "incode-electronic-signature");
//#endregion
export { ElectronicSignature as n, AeSignature as t };
