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] = "11efa216-4dc2-42d9-b27b-7f4d2b685ea3", e._sentryDebugIdIdentifier = "sentry-dbid-11efa216-4dc2-42d9-b27b-7f4d2b685ea3");
} catch (e) {}
import { n as addResourceBundles, o as createLogger, r as useTranslation } from "./translation-DYpZlvOH.js";
import { i as stylesheets, n as EmbedShell, t as resolveEnvironment } from "./resolveEnvironment-v_81BITS.js";
import { r as Loader, t as Button } from "./Button-DOLNhJTG.js";
import { r as httpPost, s as useApiContext } from "./http-BN5CG8KV.js";
import { t as _rolldown_dynamic_import_helper_default } from "./_rolldown_dynamic_import_helper-CCXvMgfE.js";
import { t as Alert } from "./Alert-CBZNxyCL.js";
import { t as emitAdyenSdkEvent } from "./emitEvent-B8K0cb1F.js";
import { t as useOnboardingStatus } from "./useOnboardingStatus-BhopZ-ko.js";
import { t as OnboardingStatuses } from "./view-verification-status-CtW_qUMg.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-DLd3BaDx.js"),
			"./language/cs-CZ.json": () => import("./cs-CZ-C6VkcCUo.js"),
			"./language/da-DK.json": () => import("./da-DK-CB-sFnhe.js"),
			"./language/de-DE.json": () => import("./de-DE-BHik7H3o.js"),
			"./language/el-GR.json": () => import("./el-GR-LUFCyvHj.js"),
			"./language/en-US.json": () => import("./en-US-B-_7IR6A.js"),
			"./language/es-ES.json": () => import("./es-ES-RzKcfNXi.js"),
			"./language/et-EE.json": () => import("./et-EE-BWE9LBIW.js"),
			"./language/fi-FI.json": () => import("./fi-FI-CfmDq95S.js"),
			"./language/fr-FR.json": () => import("./fr-FR-BqpAnmif.js"),
			"./language/hr-HR.json": () => import("./hr-HR-mfHZl8tO.js"),
			"./language/hu-HU.json": () => import("./hu-HU-yAwdJ5xn.js"),
			"./language/it-IT.json": () => import("./it-IT-BcBkbTJA.js"),
			"./language/ja-JP.json": () => import("./ja-JP-CTFB8UKL.js"),
			"./language/lt-LT.json": () => import("./lt-LT-OGBNEWvq.js"),
			"./language/lv-LV.json": () => import("./lv-LV-CcQHxQxD.js"),
			"./language/nl-NL.json": () => import("./nl-NL-DI_aNYah.js"),
			"./language/no-NO.json": () => import("./no-NO-BNL9v_bl.js"),
			"./language/pl-PL.json": () => import("./pl-PL-DeAckp5p.js"),
			"./language/pt-BR.json": () => import("./pt-BR-D8hxPoFJ.js"),
			"./language/pt-PT.json": () => import("./pt-PT-CEPDmPY7.js"),
			"./language/ro-RO.json": () => import("./ro-RO-e45j_CyV.js"),
			"./language/sk-SK.json": () => import("./sk-SK-DXRluu5W.js"),
			"./language/sl-SI.json": () => import("./sl-SI-D6evG9fK.js"),
			"./language/sv-SE.json": () => import("./sv-SE-4oyeOi4Y.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 };
