try {
	let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
	n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "2305c3a9-ec35-46e1-8d6a-9b1e28542a17", e._sentryDebugIdIdentifier = "sentry-dbid-2305c3a9-ec35-46e1-8d6a-9b1e28542a17");
} catch (e) {}
import { c as __exportAll, n as addResourceBundles, r as useTranslation } from "./translation-Br5wIPO-.js";
import { r as Loader, t as Button } from "./Button-BDEdGXnd.js";
import { r as httpPost, s as useApiContext } from "./http-CHTzpXCd.js";
import { r as useLegalEntity, t as ROOT_LE } from "./useLegalEntity-Dm6g0wmt.js";
import { t as LegalEntityTypes } from "./legal-entity-type-VIfNYnJP.js";
import { y as isEmpty } from "./validatorUtils-Dz6AklT-.js";
import { t as _rolldown_dynamic_import_helper_default } from "./_rolldown_dynamic_import_helper-CCXvMgfE.js";
import { t as TaskTypes } from "./taskTypes-DWaxzvnQ.js";
import { r as getOwnDecisionMakers } from "./decisionMakerRoles-wy4KpDQg.js";
import { n as usePciStatus, t as useSalesChannels } from "./useSalesChannels-BDg8_NCC.js";
import { t as Card } from "./Card-DXdUqwyQ.js";
import { t as useAnalyticsContext } from "./useAnalyticsContext-DfTXpZbA.js";
import { t as useToastContext } from "./useToastContext-CK7UoZ5Z.js";
import { t as EndStateLayout } from "./EndStateLayout-DxdIVWL3.js";
import { t as useInvalidateRootLegalEntity } from "./invalidateRootLegalEntity-BHyct4ev.js";
import { t as useTaskLandedEvent } from "./useTaskLandedEvent-DCdJo64z.js";
import { t as MaybeModal } from "./MaybeModal-DkRlF_Mg.js";
import { t as Field } from "./Field-BEqknhTe.js";
import { t as Select } from "./Select-CMFHti4N.js";
import { t as Checkbox } from "./Checkbox-BJJIXNHL.js";
import { t as useForm } from "./useForm-DzG9tJAE.js";
import { t as ContractViewer } from "./ContractViewer-BieoFdY1.js";
import { t as DetailViewLayout } from "./DetailViewLayout-H4b1E5Ih.js";
import { useCallback, useMemo, useState } from "preact/hooks";
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
import { useMutation, useQuery } from "@tanstack/preact-query";
//#region src/api/pci/usePciTemplate.ts
var getPciTemplate = async (legalEntityId, baseUrl, data) => {
	const filteredData = {
		...data,
		additionalSalesChannels: data.additionalSalesChannels?.filter((channel) => channel !== "payByLink")
	};
	return httpPost({
		baseUrl,
		path: `legalEntities/${legalEntityId}/pci/generatePciTemplates`
	}, filteredData);
};
var usePciTemplate = (data, options) => {
	const { rootLegalEntityId, baseUrl } = useApiContext();
	return useQuery({
		queryKey: ["pciTemplate", data],
		queryFn: () => getPciTemplate(rootLegalEntityId.value, baseUrl.value, data),
		...options
	});
};
//#endregion
//#region src/api/pci/useSignPci.ts
var signPci = async (legalEntityId, baseUrl, data) => {
	return httpPost({
		baseUrl,
		path: `legalEntities/${legalEntityId}/pci/signPciTemplates`
	}, data);
};
var useSignPci = (options) => {
	const { rootLegalEntityId, baseUrl } = useApiContext();
	const invalidateRootLegalEntity = useInvalidateRootLegalEntity();
	return useMutation({
		mutationFn: (data) => signPci(rootLegalEntityId.value, baseUrl.value, data),
		onSuccess: async () => {
			await invalidateRootLegalEntity();
		},
		...options
	});
};
//#endregion
//#region src/components/Contract/tasks/PciDropin/validate.ts
var pciValidationRules = {
	signer: {
		modes: ["blur"],
		validate: (signer) => !isEmpty(signer),
		errorMessage: "fieldIsRequired"
	},
	acceptPci: {
		modes: ["blur"],
		validate: (acceptPci) => !!acceptPci,
		errorMessage: "fieldIsRequired"
	}
};
//#endregion
//#region src/components/Contract/tasks/PciDropin/PciDropin.tsx
var PciFields = ["signer", "acceptPci"];
function PciDropin({ legalEntityResponse, pciTemplateResponse, handleHomeClick, handleSign, asModal = false, needsSigning = true, handleCloseClick }) {
	const { t } = useTranslation(["contract", "common"]);
	const userEvents = useAnalyticsContext();
	const { showToast } = useToastContext();
	const [isLoading, setIsLoading] = useState(false);
	const { handleChangeFor, triggerValidation, data, valid, isValid, errors } = useForm({
		schema: PciFields,
		rules: pciValidationRules
	});
	const { pciTemplateReferences, content } = pciTemplateResponse;
	const pciQuestionnaire = useMemo(() => JSON.parse(decodeURIComponent(escape(window.atob(content)))), [content]);
	const uniqueEntityAssociations = [...new Map(getOwnDecisionMakers(legalEntityResponse).map((entityAssociation) => [entityAssociation.legalEntityId, entityAssociation])).values()];
	const signers = legalEntityResponse.type === LegalEntityTypes.ORGANIZATION ? uniqueEntityAssociations.filter((ea) => Boolean(ea.legalEntityId && ea.name)).map(({ legalEntityId: id, name }) => ({
		id,
		name
	})) : [{
		id: legalEntityResponse.id,
		name: `${legalEntityResponse.individual?.name.firstName ?? ""} ${legalEntityResponse.individual?.name.lastName ?? ""}`
	}];
	const handleSignClick = async () => {
		if (isLoading) return;
		const baseTracking = {
			actionType: "sign",
			label: "sign"
		};
		triggerValidation();
		if (isValid) try {
			setIsLoading(true);
			await handleSign(legalEntityResponse.id, {
				signedBy: data.signer,
				pciTemplateReferences
			});
			setIsLoading(false);
			showToast({
				label: t(($) => $["pciSignedSuccessfully"]),
				variant: "success"
			});
			userEvents.addTaskEvent("Success", baseTracking);
			goHome();
		} catch (e) {
			setIsLoading(false);
			showToast({
				label: t(($) => $["signingFailed"]),
				variant: "error"
			});
			userEvents.addTaskEvent("Encountered error", {
				...baseTracking,
				returnType: e?.errorCode || "backend",
				returnValue: e?.title ?? e?.message
			});
		}
		else userEvents.addTaskEvent("Encountered error", {
			...baseTracking,
			returnType: "validation",
			returnValue: Object.entries(valid).filter(([, value]) => !value).map(([key]) => key)
		});
	};
	const goHome = () => {
		userEvents.addPageEvent("Clicked button", {
			actionType: "back",
			label: "finishLater"
		});
		handleHomeClick();
	};
	const handleExpandSection = useCallback((title) => {
		userEvents.addFieldEvent("Clicked accordion", {
			actionType: "open",
			field: title
		});
	}, []);
	/**
	* Analytics
	*/
	useTaskLandedEvent("PCI_DSS");
	const acceptPciLabel = `${t(($) => $["acknowledgePciRequirements"])} ${t(($) => $["basedOnTheAboveSignatory"])}`;
	const actions = /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Button, {
		onClick: handleSignClick,
		fullWidth: true,
		disabled: isLoading,
		children: t(($) => $["sign"], { ns: "common" })
	}), /* @__PURE__ */ jsx(Button, {
		variant: "secondary",
		onClick: goHome,
		fullWidth: true,
		children: t(($) => $["finishLater"], { ns: "common" })
	})] });
	return /* @__PURE__ */ jsx(MaybeModal, {
		inline: !asModal,
		onClose: handleCloseClick,
		inset: true,
		children: !needsSigning ? /* @__PURE__ */ jsx(EndStateLayout, {
			title: t(($) => $["agreementSigned"], { ns: "common" }),
			description: t(($) => $["pciDssSelfServiceQuestionnaireSignedSuccessfully"]),
			action: handleCloseClick && /* @__PURE__ */ jsx(Button, {
				onClick: handleCloseClick,
				fullWidth: true,
				children: t(($) => $["finish"], { ns: "common" })
			})
		}) : /* @__PURE__ */ jsxs(DetailViewLayout, {
			title: t(($) => $["pciDssSelfServiceQuestionnaire"]),
			compact: asModal,
			actions,
			children: [
				/* @__PURE__ */ jsx(Card, { children: /* @__PURE__ */ jsx(ContractViewer, {
					contract: pciQuestionnaire,
					onExpandSection: handleExpandSection
				}) }),
				/* @__PURE__ */ jsx(Field, {
					name: "signer",
					label: t(($) => $["signatory"], { ns: "common" }),
					errorMessage: errors.signer?.errorMessage,
					isValid: valid.signer,
					dataTestId: "signer",
					children: (childProps) => /* @__PURE__ */ jsx(Select, {
						...childProps,
						onChange: handleChangeFor("signer", "blur"),
						name: "signer",
						placeholder: t(($) => $["selectSigner"]),
						selected: data.signer,
						items: signers
					})
				}),
				/* @__PURE__ */ jsx(Field, {
					name: "acceptPci",
					errorMessage: errors.acceptPci?.errorMessage,
					isValid: valid.acceptPci,
					showErrorIconBottom: true,
					children: (childProps) => /* @__PURE__ */ jsx(Checkbox, {
						...childProps,
						label: acceptPciLabel,
						checked: data.acceptPci ?? false,
						name: "acceptPci",
						onChange: handleChangeFor("acceptPci")
					})
				})
			]
		})
	});
}
//#endregion
//#region src/components/EmbeddedDropins/SignPCIComponent/SignPCIComponent.tsx
var SignPCIComponent_exports = /* @__PURE__ */ __exportAll({ SignPCIComponent: () => SignPCIComponent });
function SignPCIComponent({ modalView = false, onClose, onSigned, onUnmount, selectedSalesChannels }) {
	const additionalSalesChannels = useSalesChannels();
	const { t, i18n } = useTranslation(["contract", "common"]);
	addResourceBundles(i18n, [
		{
			ns: "common",
			importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
				"../../../language/locales/bg-BG.json": () => import("./bg-BG-NwL6SZRu.js"),
				"../../../language/locales/cs-CZ.json": () => import("./cs-CZ-BZkot6xs.js"),
				"../../../language/locales/da-DK.json": () => import("./da-DK-Bc6oX5Ct.js"),
				"../../../language/locales/de-DE.json": () => import("./de-DE-JZBqb8ce.js"),
				"../../../language/locales/el-GR.json": () => import("./el-GR-C8jFvyDg.js"),
				"../../../language/locales/en-US.instructions.json": () => import("./en-US.instructions-DlxMDbRu.js"),
				"../../../language/locales/en-US.json": () => import("./en-US-Cq6Cl6Yl.js"),
				"../../../language/locales/es-ES.json": () => import("./es-ES-mdSA-CIT.js"),
				"../../../language/locales/et-EE.json": () => import("./et-EE-B4ZMHksf.js"),
				"../../../language/locales/fi-FI.json": () => import("./fi-FI-koFpyMaq.js"),
				"../../../language/locales/fr-FR.json": () => import("./fr-FR-B0eVVc8V.js"),
				"../../../language/locales/hr-HR.json": () => import("./hr-HR-D_X-RNUl.js"),
				"../../../language/locales/hu-HU.json": () => import("./hu-HU-3FpAw9b1.js"),
				"../../../language/locales/it-IT.json": () => import("./it-IT-BgULENxX.js"),
				"../../../language/locales/ja-JP.json": () => import("./ja-JP-BT70_5Cd.js"),
				"../../../language/locales/lt-LT.json": () => import("./lt-LT-CKltvr9j.js"),
				"../../../language/locales/lv-LV.json": () => import("./lv-LV-DwsdNJrk.js"),
				"../../../language/locales/nl-NL.json": () => import("./nl-NL-CxlTSECX.js"),
				"../../../language/locales/no-NO.json": () => import("./no-NO-FtH9gIpv.js"),
				"../../../language/locales/pl-PL.json": () => import("./pl-PL-CK40GB3R.js"),
				"../../../language/locales/pt-BR.json": () => import("./pt-BR-zUBVM8_b.js"),
				"../../../language/locales/pt-PT.json": () => import("./pt-PT-CxnB9Jff.js"),
				"../../../language/locales/ro-RO.json": () => import("./ro-RO-Cuw1RmFc.js"),
				"../../../language/locales/sk-SK.json": () => import("./sk-SK-1i0L4zIs.js"),
				"../../../language/locales/sl-SI.json": () => import("./sl-SI-D3zK3MPP.js"),
				"../../../language/locales/sv-SE.json": () => import("./sv-SE-CVRa-6Y0.js")
			}), `../../../language/locales/${lang}.json`, 6)
		},
		{
			ns: "ui",
			importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
				"../../ui/language/bg-BG.json": () => import("./bg-BG-IjNKw0Zu.js"),
				"../../ui/language/cs-CZ.json": () => import("./cs-CZ-B6AZX4nL.js"),
				"../../ui/language/da-DK.json": () => import("./da-DK-B8aHvZ1W.js"),
				"../../ui/language/de-DE.json": () => import("./de-DE-cPL-uSMG.js"),
				"../../ui/language/el-GR.json": () => import("./el-GR-BDXwftjw.js"),
				"../../ui/language/en-US.json": () => import("./en-US-_l9425V1.js"),
				"../../ui/language/es-ES.json": () => import("./es-ES-D67pkLVu.js"),
				"../../ui/language/et-EE.json": () => import("./et-EE-Dg93VJbx.js"),
				"../../ui/language/fi-FI.json": () => import("./fi-FI-BNtrKnDN.js"),
				"../../ui/language/fr-FR.json": () => import("./fr-FR-DYDmBWWT.js"),
				"../../ui/language/hr-HR.json": () => import("./hr-HR-DbebVQF9.js"),
				"../../ui/language/hu-HU.json": () => import("./hu-HU-e9KN8lp6.js"),
				"../../ui/language/it-IT.json": () => import("./it-IT-16IjDttL.js"),
				"../../ui/language/ja-JP.json": () => import("./ja-JP-CJY6uqPb.js"),
				"../../ui/language/lt-LT.json": () => import("./lt-LT-BVVTYN3z.js"),
				"../../ui/language/lv-LV.json": () => import("./lv-LV-BeobSRYx.js"),
				"../../ui/language/nl-NL.json": () => import("./nl-NL-DKpjFbpm.js"),
				"../../ui/language/no-NO.json": () => import("./no-NO-CG5RteG_.js"),
				"../../ui/language/pl-PL.json": () => import("./pl-PL-R6bNjSQB.js"),
				"../../ui/language/pt-BR.json": () => import("./pt-BR-VlNZLr8f.js"),
				"../../ui/language/pt-PT.json": () => import("./pt-PT-Dmor9x6o.js"),
				"../../ui/language/ro-RO.json": () => import("./ro-RO-BRtHlgch.js"),
				"../../ui/language/sk-SK.json": () => import("./sk-SK--ohjuOMW.js"),
				"../../ui/language/sl-SI.json": () => import("./sl-SI-DWJzi8r_.js"),
				"../../ui/language/sv-SE.json": () => import("./sv-SE-DTpqjuJd.js")
			}), `../../ui/language/${lang}.json`, 5)
		},
		{
			ns: "contract",
			importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
				"../../Contract/language/bg-BG.json": () => import("./bg-BG-mf-xq3ph.js"),
				"../../Contract/language/cs-CZ.json": () => import("./cs-CZ-B_nYIuIi.js"),
				"../../Contract/language/da-DK.json": () => import("./da-DK-CBt4gQjw.js"),
				"../../Contract/language/de-DE.json": () => import("./de-DE-D8Is4iJk.js"),
				"../../Contract/language/el-GR.json": () => import("./el-GR-BZ9AJNm4.js"),
				"../../Contract/language/en-US.json": () => import("./en-US-BhctnSAK.js"),
				"../../Contract/language/es-ES.json": () => import("./es-ES-B2MIlPdM.js"),
				"../../Contract/language/et-EE.json": () => import("./et-EE-Lw-rTsG-.js"),
				"../../Contract/language/fi-FI.json": () => import("./fi-FI-TDF0ZiiC.js"),
				"../../Contract/language/fr-FR.json": () => import("./fr-FR-fwcu0Hmd.js"),
				"../../Contract/language/hr-HR.json": () => import("./hr-HR-dL_cUkZa.js"),
				"../../Contract/language/hu-HU.json": () => import("./hu-HU-ReTWA1v3.js"),
				"../../Contract/language/it-IT.json": () => import("./it-IT-C2JfprsD.js"),
				"../../Contract/language/ja-JP.json": () => import("./ja-JP-BRGxY7zc.js"),
				"../../Contract/language/lt-LT.json": () => import("./lt-LT-_MAUl9-y.js"),
				"../../Contract/language/lv-LV.json": () => import("./lv-LV-Br4-Sv0n.js"),
				"../../Contract/language/nl-NL.json": () => import("./nl-NL-ByNQn3Ma.js"),
				"../../Contract/language/no-NO.json": () => import("./no-NO-CX2Lkpbt.js"),
				"../../Contract/language/pl-PL.json": () => import("./pl-PL-W0KU0YTp.js"),
				"../../Contract/language/pt-BR.json": () => import("./pt-BR-CdeMGenL.js"),
				"../../Contract/language/pt-PT.json": () => import("./pt-PT-BEkfXdZQ.js"),
				"../../Contract/language/ro-RO.json": () => import("./ro-RO-tf_g2ahZ.js"),
				"../../Contract/language/sk-SK.json": () => import("./sk-SK-DaSC7QsL.js"),
				"../../Contract/language/sl-SI.json": () => import("./sl-SI-C6KiyZyh.js"),
				"../../Contract/language/sv-SE.json": () => import("./sv-SE-CTB2971Y.js")
			}), `../../Contract/language/${lang}.json`, 5)
		}
	]);
	const { data: legalEntityData, isError: isLegalEntityError, isLoading: isLegalEntityLoading } = useLegalEntity(ROOT_LE);
	const allSalesChannels = useMemo(() => {
		return [...new Set([...additionalSalesChannels, ...selectedSalesChannels ?? []])];
	}, [additionalSalesChannels, selectedSalesChannels]);
	const { data: pciTemplateData, isLoading: isPciTemplateDataLoading } = usePciTemplate({
		additionalSalesChannels: allSalesChannels,
		language: i18n.language.substring(0, 2) ?? "en"
	});
	const { data: pciStatusData, isLoading: isPciStatusLoading, isError: isPciStatusError } = usePciStatus({ additionalSalesChannels: allSalesChannels });
	const signPci = useSignPci();
	const handleOnClose = () => {
		if (modalView) onUnmount?.();
		onClose?.();
	};
	if (isLegalEntityLoading || isPciStatusLoading || isPciTemplateDataLoading || !legalEntityData || !pciTemplateData) return /* @__PURE__ */ jsx(Loader, {});
	if (isLegalEntityError || isPciStatusError) return /* @__PURE__ */ jsx(MaybeModal, {
		inline: !modalView,
		onClose: handleOnClose,
		children: /* @__PURE__ */ jsx(EndStateLayout, {
			title: t(($) => $["nothingNeedsToBeSigned"]),
			description: t(($) => $["pciDoesNotNeedSigningOrHasBeenSigned"], { ns: "common" }),
			action: /* @__PURE__ */ jsx(Button, {
				onClick: handleOnClose,
				fullWidth: true,
				children: t(($) => $["finish"], { ns: "common" })
			})
		})
	});
	return /* @__PURE__ */ jsx(PciDropin, {
		taskType: TaskTypes.PCI_DSS,
		legalEntityResponse: legalEntityData,
		pciTemplateResponse: pciTemplateData,
		handleHomeClick: handleOnClose,
		handleSign: async (_legalEntityId, signedBy) => {
			await signPci.mutateAsync(signedBy);
			onUnmount?.();
			onSigned?.();
		},
		handleCloseClick: handleOnClose,
		asModal: modalView,
		needsSigning: Boolean(pciStatusData?.signingRequired)
	});
}
//#endregion
export { SignPCIComponent_exports as n, SignPCIComponent as t };
