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] = "50a49ba7-e0aa-428f-8027-35abd1da6332", e._sentryDebugIdIdentifier = "sentry-dbid-50a49ba7-e0aa-428f-8027-35abd1da6332");
} catch (e) {}
import { n as addResourceBundles, o as createLogger, r as useTranslation } from "./translation-Br5wIPO-.js";
import { i as stylesheets, n as EmbedShell, t as resolveEnvironment } from "./resolveEnvironment-BcrJH82n.js";
import { r as Loader, t as Button } from "./Button-BDEdGXnd.js";
import { r as httpPost, s as useApiContext } from "./http-CHTzpXCd.js";
import { t as _rolldown_dynamic_import_helper_default } from "./_rolldown_dynamic_import_helper-CCXvMgfE.js";
import { t as Alert } from "./Alert-CjZYipjN.js";
import { t as emitAdyenSdkEvent } from "./emitEvent-DYC1em5m.js";
import { t as useOnboardingStatus } from "./useOnboardingStatus-CdLObhIM.js";
import { t as OnboardingStatuses } from "./view-verification-status-C3zAZhYk.js";
import register from "preact-custom-element";
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
import { useMutation } from "@tanstack/preact-query";
//#region src/api/onboardingStatus/useGenerateOnboardingLink.ts
var generateOnboardingLink = async (legalEntityId, baseUrl, data) => {
	return httpPost({
		baseUrl,
		path: `legalEntities/${legalEntityId}/onboardingStatus`
	}, data);
};
var useGenerateOnboardingLink = (options) => {
	const { rootLegalEntityId, baseUrl } = useApiContext();
	return useMutation({
		mutationFn: (data) => generateOnboardingLink(rootLegalEntityId.value, baseUrl.value, data),
		...options
	});
};
//#endregion
//#region src/utils/coerceError.ts
var coerceError = (err) => {
	if (err instanceof Error) return err;
	if (typeof err === "object") {
		if (err !== null && "message" in err && typeof err.message === "string") return new Error(err.message);
	}
	return /* @__PURE__ */ new Error("Unknown error");
};
//#endregion
//#region src/components/EmbeddedDropins/ViewVerificationStatus/content.ts
var contentMap = {
	[OnboardingStatuses.AWAITING_DATA]: {
		description: ["onboardingRedirectAwaitingDescriptionP1"],
		ctaButton: "onboardingRedirectAwaitingCtaButton"
	},
	[OnboardingStatuses.IN_REVIEW]: {
		description: ["onboardingRedirectInReviewDescriptionP1"],
		ctaButton: "onboardingRedirectInReviewCtaButton"
	},
	[OnboardingStatuses.UNSUCCESSFUL]: {
		description: ["onboardingRedirectUnsuccessfulDescriptionP1"],
		ctaButton: "onboardingRedirectUnsuccessfulCtaButton"
	},
	[OnboardingStatuses.REJECTED]: { description: ["onboardingRedirectRejectedDescriptionP1"] },
	[OnboardingStatuses.VERIFIED]: { description: ["onboardingRedirectVerifiedDescriptionP1"] }
};
function getContentByStatus(status) {
	return contentMap[status];
}
var ViewVerificationStatusComponent_module_default = {
	verification: "adyen-kyc-verification",
	"verification-description": "adyen-kyc-verification-description",
	verificationDescription: "adyen-kyc-verification-description"
};
//#endregion
//#region src/components/EmbeddedDropins/ViewVerificationStatus/ViewVerificationStatusComponent.tsx
var FINAL_STATUSES = [OnboardingStatuses.VERIFIED, OnboardingStatuses.REJECTED];
var logger = createLogger();
function ViewVerificationStatusComponent({ legalEntityId, hideExplanation = false, returnUrl, redirectTarget = "_blank", themeId, onStatusChange, onError, onRedirect }) {
	const { i18n, t } = useTranslation("verificationStatus");
	addResourceBundles(i18n, [{
		ns: "verificationStatus",
		importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
			"./language/bg-BG.json": () => import("./bg-BG-CogcfR3g.js"),
			"./language/cs-CZ.json": () => import("./cs-CZ-D73bqvvS.js"),
			"./language/da-DK.json": () => import("./da-DK-CxoaLz6P.js"),
			"./language/de-DE.json": () => import("./de-DE-BxL8NQIq.js"),
			"./language/el-GR.json": () => import("./el-GR-DvIXL8AR.js"),
			"./language/en-US.json": () => import("./en-US-DHD_ENM1.js"),
			"./language/es-ES.json": () => import("./es-ES-CAuzNvPf.js"),
			"./language/et-EE.json": () => import("./et-EE-DCEDrMl2.js"),
			"./language/fi-FI.json": () => import("./fi-FI-DZ5-w9vt.js"),
			"./language/fr-FR.json": () => import("./fr-FR-BshpJ5Y8.js"),
			"./language/hr-HR.json": () => import("./hr-HR-D6jMCNOJ.js"),
			"./language/hu-HU.json": () => import("./hu-HU-Cy8F1a5a.js"),
			"./language/it-IT.json": () => import("./it-IT-C75KiNnW.js"),
			"./language/ja-JP.json": () => import("./ja-JP-CjEZToEj.js"),
			"./language/lt-LT.json": () => import("./lt-LT-CB33emTJ.js"),
			"./language/lv-LV.json": () => import("./lv-LV-DIopAlNr.js"),
			"./language/nl-NL.json": () => import("./nl-NL-BKmH_4rF.js"),
			"./language/no-NO.json": () => import("./no-NO-DjTYr6zQ.js"),
			"./language/pl-PL.json": () => import("./pl-PL-C_ys8FVH.js"),
			"./language/pt-BR.json": () => import("./pt-BR-Bb7L6a3z.js"),
			"./language/pt-PT.json": () => import("./pt-PT-CFcpXSKo.js"),
			"./language/ro-RO.json": () => import("./ro-RO-CT5uU3Rj.js"),
			"./language/sk-SK.json": () => import("./sk-SK-DkianEJG.js"),
			"./language/sl-SI.json": () => import("./sl-SI-Br0agZj0.js"),
			"./language/sv-SE.json": () => import("./sv-SE-CWkxvOEr.js")
		}), `./language/${lang}.json`, 3)
	}]);
	const { rootLegalEntityId: currentLegalEntityId } = useApiContext();
	currentLegalEntityId.value = legalEntityId;
	const config = {
		locale: i18n.language,
		returnUrl,
		themeId
	};
	const [onboardingStatus, setOnboardingStatus] = useState();
	const [alertContent, setAlertContent] = useState();
	const content = useMemo(() => {
		if (!onboardingStatus) return;
		const statusContent = getContentByStatus(onboardingStatus);
		if (statusContent) return statusContent;
		logger.error(`there is no content for status "${onboardingStatus}"`);
	}, [onboardingStatus]);
	const handleError = useCallback((rawError, userMessage) => {
		const error = coerceError(rawError);
		logger.error(error);
		setAlertContent(userMessage);
		onError?.({
			error,
			userMessage: t(($) => $[userMessage])
		});
	}, [t, onError]);
	const updateOnboardingStatus = useCallback((newStatus) => {
		if (!newStatus) return;
		setOnboardingStatus(newStatus);
		if (newStatus !== onboardingStatus) onStatusChange?.(newStatus);
	}, [onStatusChange, onboardingStatus]);
	const { isLoading, data, isError } = useOnboardingStatus({ refetchInterval: (res) => {
		const status = res.state.data?.status;
		setOnboardingStatus(status);
		return status === void 0 || !FINAL_STATUSES.includes(status) ? 3e3 : false;
	} });
	useEffect(() => {
		setAlertContent(void 0);
		updateOnboardingStatus(data?.status);
	}, [data, updateOnboardingStatus]);
	const generateOnboardingLink = useGenerateOnboardingLink({
		onSuccess: ({ redirectUrl }) => {
			if (!redirectUrl) {
				handleError(/* @__PURE__ */ new Error("No redirectUrl returned"), "onboardingRedirectLinkError");
				return;
			}
			openUrl(redirectUrl, config);
		},
		onError: (error) => {
			handleError(error, "onboardingRedirectLinkError");
		}
	});
	const openUrl = (url, config) => {
		if (!window.open(url, redirectTarget)) {
			handleError(/* @__PURE__ */ new Error("Could not open redirect in new tab"), "onboardingRedirectOpenError");
			return;
		}
		onRedirect?.({
			...config,
			onboardingLink: url
		});
	};
	const showAlert = alertContent || isError;
	const hideButton = onboardingStatus === OnboardingStatuses.REJECTED || onboardingStatus === OnboardingStatuses.VERIFIED || !content?.ctaButton;
	if (!showAlert && (isLoading || !content)) return /* @__PURE__ */ jsx(Loader, {});
	return /* @__PURE__ */ jsx("section", {
		className: ViewVerificationStatusComponent_module_default.verification,
		children: showAlert ? /* @__PURE__ */ jsx(Alert, {
			title: t(($) => $[alertContent ?? "onboardingRedirectLinkError"]),
			variant: "error"
		}) : /* @__PURE__ */ jsxs(Fragment, { children: [!hideExplanation && content?.description.map((key) => /* @__PURE__ */ jsx("p", {
			className: ViewVerificationStatusComponent_module_default.verificationDescription,
			children: t(($) => $[key])
		}, key)), !hideButton && /* @__PURE__ */ jsx(Button, {
			onClick: () => {
				generateOnboardingLink.mutate(config);
			},
			variant: "link",
			loading: generateOnboardingLink.isPending,
			children: t(($) => $[content.ctaButton])
		})] })
	});
}
//#endregion
//#region src/embeds/verification-status/adyen-verification-status.tsx
var AdyenVerificationStatus = ({ rootlegalentityid, fetchToken, environment, locale, settings = {}, experiments = {}, hideexplanation, returnurl, redirecttarget, themeid }) => {
	const eventEmitterRef = useRef(null);
	const handleOnChange = (data) => {
		emitAdyenSdkEvent(eventEmitterRef, "change", data);
	};
	const handleOnError = (data) => {
		emitAdyenSdkEvent(eventEmitterRef, "error", data);
	};
	const handleOnRedirect = (data) => {
		emitAdyenSdkEvent(eventEmitterRef, "redirect", data);
	};
	return /* @__PURE__ */ jsx("div", {
		ref: eventEmitterRef,
		style: "width:100%;",
		children: /* @__PURE__ */ jsx(EmbedShell, {
			componentName: "adyen-verification-status",
			rootLegalEntityId: rootlegalentityid,
			settings,
			features: experiments,
			getSdkToken: fetchToken,
			locale,
			baseUrl: resolveEnvironment(environment),
			children: /* @__PURE__ */ jsx(ViewVerificationStatusComponent, {
				legalEntityId: rootlegalentityid,
				hideExplanation: hideexplanation,
				returnUrl: returnurl,
				redirectTarget: redirecttarget,
				themeId: themeid,
				onStatusChange: handleOnChange,
				onError: handleOnError,
				onRedirect: handleOnRedirect
			})
		})
	});
};
register(AdyenVerificationStatus, "adyen-verification-status", [
	"rootlegalentityid",
	"fetchToken",
	"environment",
	"locale",
	"settings",
	"experiments",
	"hideexplanation",
	"returnurl",
	"redirecttarget",
	"themeid"
], {
	shadow: true,
	adoptedStyleSheets: stylesheets
});
//#endregion
export { AdyenVerificationStatus };
