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] = "e6cab66d-8611-454c-ba35-65c11dc33f90", e._sentryDebugIdIdentifier = "sentry-dbid-e6cab66d-8611-454c-ba35-65c11dc33f90");
} catch (e) {}
import { o as createLogger } from "./translation-Br5wIPO-.js";
import { t as CountryCodes } from "./country-code-D3oCpE4i.js";
import { t as useScenarios } from "./useScenarios-Bb-EhIep.js";
import { useEffect, useMemo, useState } from "preact/hooks";
import { signal } from "@preact/signals";
//#region src/core/error.ts
var AdyenKycSdkError = class extends Error {
	sourceError;
	constructor(message, sourceError) {
		super(message);
		this.name = this.constructor.name;
		this.sourceError = sourceError;
		const stack = [];
		if (sourceError) {
			if (sourceError instanceof this.constructor) stack.push(`${this.name}: ${sourceError.message}`);
			if (sourceError.stack) stack.push(sourceError.stack);
		}
		this.stack = stack.join("\n");
	}
};
//#endregion
//#region src/components/BankAccount/forms/PayoutAccount/payoutAccountFormat.ts
var payoutAccountFormat = signal("local");
//#endregion
//#region src/components/BankAccount/utils/defaultPayoutAccountFormat.ts
var defaultPayoutAccountFormat = {
	[CountryCodes.CzechRepublic]: "iban",
	[CountryCodes.Denmark]: "local",
	[CountryCodes.Hungary]: "iban",
	[CountryCodes.Norway]: "local",
	[CountryCodes.Poland]: "local",
	[CountryCodes.Sweden]: "local",
	[CountryCodes.UnitedKingdom]: "local"
};
//#endregion
//#region src/hooks/useUnifyLoadingStatus.ts
var useUnifyLoadingStatus = (setParentLoadingStatus, ...childLoadingStatuses) => {
	useEffect(() => {
		setParentLoadingStatus(childLoadingStatuses.some((status) => status === "loading" || status === "pending") ? "loading" : "success");
	}, [...childLoadingStatuses]);
};
//#endregion
//#region src/hooks/useScenarioConfiguration.ts
var logger = createLogger();
var useScenarioConfiguration = ({ getPayoutAccountFormatData, parseConfiguration, country, legalEntityType, instantVerificationAvailable, setLoadingStatus, existingBankAccountFormat }) => {
	const accountFormat = payoutAccountFormat.value;
	const { data: scenarios, isLoading: scenariosIsLoading, isError: scenariosIsError } = useScenarios(country, legalEntityType);
	const [accountFormatResponse, setAccountFormatResponse] = useState();
	const configurationLoadingStatus = useMemo(() => {
		if (scenariosIsLoading) return "loading";
		if (scenariosIsError) return "error";
		if (scenarios) return "success";
		return "pending";
	}, [
		scenarios,
		scenariosIsError,
		scenariosIsLoading
	]);
	const [payoutFormatLoadingStatus, setpayoutFormatLoadingStatus] = useState("success");
	useUnifyLoadingStatus(setLoadingStatus, configurationLoadingStatus, payoutFormatLoadingStatus);
	useEffect(() => {
		if (!getPayoutAccountFormatData) return;
		setpayoutFormatLoadingStatus("loading");
		const makePayoutFormatCallAndSave = async () => {
			try {
				const response = await getPayoutAccountFormatData();
				setAccountFormatResponse(response);
				const allowedBankAccountFormats = Object.keys(response);
				if (existingBankAccountFormat && !allowedBankAccountFormats.includes(existingBankAccountFormat)) throw new AdyenKycSdkError(`Account format, ${existingBankAccountFormat}, of transferInstrument is not in allowed formats for ${country}`);
				const defaultAccountFormat = defaultPayoutAccountFormat[country] ?? allowedBankAccountFormats[0];
				payoutAccountFormat.value = existingBankAccountFormat ?? defaultAccountFormat;
			} catch (err) {
				logger.warn("WARNING: Payout format request failed - error:", err);
			} finally {
				setpayoutFormatLoadingStatus("success");
			}
		};
		makePayoutFormatCallAndSave().catch(logger.error);
	}, [
		country,
		getPayoutAccountFormatData,
		setpayoutFormatLoadingStatus,
		existingBankAccountFormat
	]);
	const { fieldConfigurations, requiredFields } = useMemo(() => {
		if (!scenarios) return {};
		const payoutRequiredFields = accountFormatResponse ? accountFormatResponse[accountFormat] : void 0;
		return {
			fieldConfigurations: parseConfiguration(payoutRequiredFields ? {
				scenarios,
				country,
				requiredFields: payoutRequiredFields,
				bankVerificationAvailable: instantVerificationAvailable
			} : {
				scenarios,
				country,
				requiredFields: void 0,
				bankVerificationAvailable: void 0
			}),
			requiredFields: payoutRequiredFields
		};
	}, [
		accountFormatResponse,
		accountFormat,
		scenarios,
		country,
		parseConfiguration,
		instantVerificationAvailable
	]);
	return {
		requiredFields,
		fieldConfigurations
	};
};
//#endregion
//#region src/utils/mapping/getPage.ts
var getPage = ({ attachments }, pageType) => {
	if (!attachments) throw Error("Document has no attachments");
	const attachment = pageType ? attachments.find((attach) => attach.pageType === pageType) : attachments[0];
	if (!attachment) throw Error(`Attachment not found${pageType ? ` with type '${pageType}'` : ""}`);
	return attachment;
};
var getPageName = (document, pageType) => getPage(document, pageType).pageName ?? "";
//#endregion
//#region src/utils/mapping/mapExistingFile.ts
var mapExistingFile = (name) => ({
	name,
	existing: true
});
//#endregion
export { useUnifyLoadingStatus as a, useScenarioConfiguration as i, getPage as n, payoutAccountFormat as o, getPageName as r, AdyenKycSdkError as s, mapExistingFile as t };
