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] = "296ef2e9-68f4-499a-9fac-a2e0940b8b20", e._sentryDebugIdIdentifier = "sentry-dbid-296ef2e9-68f4-499a-9fac-a2e0940b8b20");
} catch (e) {}
import { a as Icon, r as useTranslation } from "./translation-Br5wIPO-.js";
import { t as useAccountHolder } from "./useAccountHolder-BUQwFdWW.js";
import { o as objectsDeepEqual } from "./AnalyticsContext-C0HNdPss.js";
import { t as useToggleContext } from "./useToggleContext-CLfowItk.js";
import { t as Header } from "./Header-B_MIsVov.js";
import { t as getNestedPropertyKeys } from "./getNestedPropertyKeys-hT40QMb1.js";
import { t as CompanyTypesValues } from "./company-types-value-B-nraMaa.js";
import { t as Image } from "./Image-BPAtdM5Y.js";
import { n as translateTranslatable } from "./utils-g_Wl4-9Z.js";
import { t as ErrorPanel } from "./ErrorPanel-5g1eTEVD.js";
import { t as createFormUtils } from "./formUtils-DERTAXyh.js";
import { t as MaskedInput } from "./MaskedInput-uN8G9HRq.js";
import { a as StateContextSetter } from "./validate-DlG5LXuM.js";
import { S as taxInformationDefaultFieldMetadata, a as COUNTRIES_WITH_POSSIBLE_TRUSTEE_TAXID_ABSENT_V4, h as getTaxIdNumberOptions, m as getDefaultTaxIdNumberType, n as upsertTaxInfoForCountry, r as TaxIdNumberTypeSelector, t as removeTaxInfoForCountry, x as taxInformationDefaultFieldConfig } from "./utils-CkQJVYhR.js";
import { t as resolveFieldMetadata } from "./fieldConfigurations-B3oqm4GC.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 TextArea } from "./TextArea-qzKHJyZG.js";
import { t as useForm } from "./useForm-DzG9tJAE.js";
import { t as Dropzone } from "./Dropzone-D8gz-OLM.js";
import { lazy, memo } from "preact/compat";
import { useCallback as useCallback$1, useEffect as useEffect$1, useMemo as useMemo$1, useRef as useRef$1, useState as useState$1 } from "preact/hooks";
import cx from "classnames";
import { Fragment as Fragment$1, jsx, jsxs } from "preact/jsx-runtime";
//#region src/utils/getFieldsWithExistingData.ts
var getFieldsWithExistingData = (legalEntity, keyMapping, documentMapping, knownProblematicFields = []) => {
	const nonDocumentFields = getNestedPropertyKeys(legalEntity).map((field) => keyMapping[field]).filter(Boolean).filter((field) => !knownProblematicFields.includes(field));
	if (documentMapping && legalEntity.documentDetails?.length) {
		const documentFields = legalEntity.documentDetails.map((document) => documentMapping[document.type]).filter(Boolean);
		return [...nonDocumentFields, ...documentFields];
	}
	return nonDocumentFields;
};
//#endregion
//#region src/utils/mapping/documentGuidanceMap.ts
/**
* Returns the appropriate prefix for the document guidance image based on api documentType.
*/
var getDocumentGuidancePrefix = (documentType) => {
	switch (documentType) {
		case "passport": return "passport";
		case "driversLicense":
		case "identityCard": return "id";
		default: return "document";
	}
};
//#endregion
//#region src/components/ui/molecules/DocumentGuidance/DocumentGuidance.tsx
var documentMap = {
	"document-blurred": lazy(() => import("./document-blurred-DHgG-aQ6.js")),
	"document-cutoff": lazy(() => import("./document-cut-off-DCf-G-0l.js")),
	"document-expired": lazy(() => import("./document-expired-UJMQKi88.js")),
	"document-front": lazy(() => import("./document-front-DLpxfBfu.js")),
	"id-blurred": lazy(() => import("./id-blurred-BdqQKk1l.js")),
	"id-cutoff": lazy(() => import("./id-cut-off-BlpfXo5W.js")),
	"id-front": lazy(() => import("./id-front-Bqd59AfN.js")),
	"id-glare": lazy(() => import("./id-glare-7GGletdB.js")),
	"passport-blurred": lazy(() => import("./passport-blurred-UX6p2KZ5.js")),
	"passport-cutoff": lazy(() => import("./passport-cut-off-C4H57LgT.js")),
	"passport-front": lazy(() => import("./passport-front-K9nDuC3A.js")),
	"passport-glare": lazy(() => import("./passport-glare-Cw4IMJSe.js"))
};
function DocumentGuidance({ type, className }) {
	const { t } = useTranslation("ui");
	const documentGuidanceItems = useMemo$1(() => {
		const guidancePrefix = getDocumentGuidancePrefix(type);
		const guidanceItems = [
			{
				svgName: `${guidancePrefix}-front`,
				translationKey: "good",
				valid: true
			},
			{
				svgName: `${guidancePrefix}-cutoff`,
				translationKey: "notCutOff"
			},
			{
				svgName: `${guidancePrefix}-blurred`,
				translationKey: "notBlurry"
			},
			guidancePrefix === "document" ? {
				svgName: `document-expired`,
				translationKey: "notExpired"
			} : {
				svgName: `${guidancePrefix}-glare`,
				translationKey: "noGlare"
			}
		];
		return type === "constitutionalDocument" ? guidanceItems.filter((item) => item.svgName !== "document-expired") : guidanceItems;
	}, [type]);
	return /* @__PURE__ */ jsx("div", {
		className: cx("adyen-kyc-document-guidance", className),
		children: /* @__PURE__ */ jsx("div", {
			className: "adyen-kyc-document-guidance__container",
			children: documentGuidanceItems.map((item) => /* @__PURE__ */ jsxs("figure", {
				className: "adyen-kyc-document-guidance__item",
				children: [/* @__PURE__ */ jsx(Image, { lazyLoadedImage: documentMap[item.svgName] }), /* @__PURE__ */ jsxs("figcaption", {
					className: "adyen-kyc-document-guidance__description",
					children: [item.valid ? /* @__PURE__ */ jsx(Icon, {
						name: "check",
						className: "adyen-kyc-document-guidance__icon"
					}) : /* @__PURE__ */ jsx(Icon, {
						name: "cross",
						className: "adyen-kyc-document-guidance__icon adyen-kyc-document-guidance__icon--invalid"
					}), /* @__PURE__ */ jsx("span", {
						className: "adyen-kyc-document-guidance__description-text",
						children: t(($) => $[item.translationKey])
					})]
				})]
			}, item.translationKey))
		})
	});
}
var DocumentUpload_module_default = {
	"description-field": "adyen-kyc-description-field",
	descriptionField: "adyen-kyc-description-field"
};
//#endregion
//#region src/components/Shared/forms/DocumentUpload/DocumentUpload.tsx
var DESCRIPTION_CHARACTERS_LIMIT = 200;
function DocumentUpload({ documentType, documentField, guidanceHeader, documentTypeSelect, guidanceContent, handleFieldChange, requiredFields, data: dataProp, valid: validProp, errors: errorProp, fieldValidationErrors: propFieldValidationErrors, supportsMultipleUploads, maxNumberOfFiles = 1, label, extraDropzoneDescription, hidePageCount, ...props }) {
	const { t } = useTranslation("common");
	const [document, setDocument] = useState$1();
	const form = useForm({
		...props,
		schema: ["description"],
		defaultData: dataProp,
		rules: props.validators,
		fieldProblems: propFieldValidationErrors
	});
	const { handleChangeFor, triggerValidation, setData } = form;
	let { data, errors, valid, fieldProblems } = form;
	const formUtils = createFormUtils(props, t);
	const stateRef = useRef$1({ setState: null });
	const isOptional = !(props?.formVerificationErrors && Object.keys(props?.formVerificationErrors)?.length === 0);
	useEffect$1(() => {
		if (isOptional) triggerValidation();
	}, [dataProp]);
	useEffect$1(() => {
		stateRef.current.setState?.({
			type: "addToState",
			value: {
				data,
				valid,
				errors,
				fieldProblems,
				dataStoreId: props.id,
				schema: requiredFields
			}
		});
	}, [
		data,
		valid,
		errors,
		fieldProblems
	]);
	useEffect$1(() => {
		setDocument({ [documentField]: dataProp?.[documentField] });
		setData("description", dataProp?.description);
		triggerValidation();
	}, [dataProp]);
	if (handleFieldChange && requiredFields && propFieldValidationErrors) {
		data = dataProp ?? {};
		errors = errorProp;
		valid = validProp;
		fieldProblems = propFieldValidationErrors;
	}
	const handleInput = (e) => {
		handleChangeFor("description")(e);
		if (handleFieldChange) handleFieldChange?.("description")(e);
	};
	return /* @__PURE__ */ jsxs("div", {
		className: `adyen-kyc-company-document-upload adyen-kyc-company-document-upload--${documentField}`,
		children: [
			/* @__PURE__ */ jsx(StateContextSetter, {
				owner: props.id,
				stateRef
			}),
			props.heading && /* @__PURE__ */ jsx(Header, {
				title: props.heading,
				description: props.description
			}),
			/* @__PURE__ */ jsx(ErrorPanel, {
				verificationErrors: props?.formVerificationErrors,
				validationErrors: propFieldValidationErrors,
				formUtils,
				id: "ariaErrorField"
			}),
			formUtils.isRequiredField(documentField) && /* @__PURE__ */ jsxs(Fragment$1, { children: [
				guidanceHeader,
				documentTypeSelect && /* @__PURE__ */ jsx(Field, {
					name: "documentType",
					label: t(($) => $["selectDocumentType"]),
					children: (childProps) => /* @__PURE__ */ jsx(Select, {
						...childProps,
						onChange: (e) => documentTypeSelect.setSelectedType(e.target.value),
						name: "documentType",
						placeholder: t(($) => $["selectDocument"]),
						selected: documentTypeSelect.selectedType,
						items: documentTypeSelect.options.map(({ id, name }) => ({
							id,
							name: t(($) => $[name])
						}))
					})
				}),
				/* @__PURE__ */ jsx("div", { children: guidanceContent }),
				/* @__PURE__ */ jsx(DocumentGuidance, {
					type: documentType,
					className: "u-margin-bottom-24"
				}),
				/* @__PURE__ */ jsx(Dropzone, {
					defaultData: document ?? data,
					id: props.id,
					isOptional: isOptional || formUtils.isOptionalField(documentField),
					maxSize: documentType === "constitutionalDocument" ? 31457280 : void 0,
					name: documentField,
					shouldValidate: props.shouldValidate,
					handleFieldChange,
					errors,
					fieldValidationErrors: fieldProblems,
					valid,
					multiple: supportsMultipleUploads,
					maxNumberOfFiles: maxNumberOfFiles ?? 1,
					label,
					extraDropzoneDescription,
					hidePageCount
				})
			] }),
			formUtils.isRequiredField("description") && /* @__PURE__ */ jsx("div", {
				className: DocumentUpload_module_default.descriptionField,
				children: /* @__PURE__ */ jsx(Field, {
					name: "description",
					label: formUtils.getLabel("descriptionOptional"),
					errorMessage: formUtils.getErrorMessage("description", errors, fieldProblems),
					isValid: valid.description,
					children: (childProps) => /* @__PURE__ */ jsx(TextArea, {
						...childProps,
						name: "description",
						value: data.description,
						maxLength: DESCRIPTION_CHARACTERS_LIMIT,
						onInput: handleInput,
						"aria-invalid": !valid.description,
						handleFieldChange: handleInput,
						errors,
						fieldValidationErrors: fieldProblems,
						valid
					})
				})
			})
		]
	});
}
var MemoizedDocumentUpload = memo(DocumentUpload, (prevProps, nextProps) => prevProps.shouldValidate === nextProps.shouldValidate && objectsDeepEqual(prevProps.requiredFields, nextProps.requiredFields) && objectsDeepEqual(prevProps.errors, nextProps.errors) && objectsDeepEqual(prevProps.optionalFields, nextProps.optionalFields) && objectsDeepEqual(prevProps.data, nextProps.data) && objectsDeepEqual(prevProps.formVerificationErrors, nextProps.formVerificationErrors) && objectsDeepEqual(prevProps.fieldValidationErrors, nextProps.fieldValidationErrors) && objectsDeepEqual(prevProps.documentTypeSelect, nextProps.documentTypeSelect) && prevProps.documentField === nextProps.documentField && prevProps.name === nextProps.name && prevProps.country === nextProps.country && prevProps.companyType === nextProps.companyType);
//#endregion
//#region src/components/Shared/fields/TaxInformationField/TaxInformationField.tsx
var TAX_INFORMATION_FIELD = [
	"taxInformation",
	"exemptedFromTax",
	"isUen"
];
/**
* Renders a dynamic form field for tax identification information, adapting its display
* and behavior based on country and company type. It supports various tax ID input
* scenarios, including two specialized handling for US Sole Proprietorships (where SSN option acts as exemption selection)
* and Singapore Companies (where registration number (UEN) can be used for tax ID).
*/
function TaxInformationField({ data, valid, errors, labels, mask, placeholder, readonly, optional, shouldValidate, handleChangeFor, country, canExempt, registrationNumber, entityType, invertCompanyTypeFilter, defaultData }) {
	const { isFeatureEnabled } = useToggleContext();
	const { t } = useTranslation("common");
	const { accountHolder } = useAccountHolder();
	const currentCountryTaxInformation = useMemo$1(() => data?.taxInformation?.find((taxInfo) => taxInfo.country === country) ?? (!data.exemptedFromTax ? defaultData?.find((taxInfo) => taxInfo.country === country) : void 0), [
		data?.taxInformation,
		data.exemptedFromTax,
		defaultData,
		country
	]);
	const isUsSoleProp = country === "US" && entityType === CompanyTypesValues.SOLE_PROPRIETORSHIP;
	const options = getTaxIdNumberOptions(country, entityType, invertCompanyTypeFilter);
	const showTaxIdExemptedOptions = canExempt && (options?.length ?? 0) > 1 || isUsSoleProp;
	const canSaveAbsentState = isFeatureEnabled("EnableRegistrationAndTaxAbsentStatesV4") && COUNTRIES_WITH_POSSIBLE_TRUSTEE_TAXID_ABSENT_V4.includes(country) && accountHolder === "aTrust";
	const exemptionLabel = isUsSoleProp ? t(($) => $["socialSecurityNumber"]) : labels.exemptedFromTax;
	const shouldRenderInput = isUsSoleProp ? currentCountryTaxInformation?.type === "EIN" : !data.isUen;
	const taxIdNumberType = useMemo$1(() => {
		if (data.exemptedFromTax) return "exempted";
		if (currentCountryTaxInformation?.type) return currentCountryTaxInformation.type;
		if (isUsSoleProp) return void 0;
		return getDefaultTaxIdNumberType(data.taxInformation, country, entityType, invertCompanyTypeFilter);
	}, [
		country,
		currentCountryTaxInformation?.type,
		data.exemptedFromTax,
		data.taxInformation,
		entityType,
		invertCompanyTypeFilter,
		isUsSoleProp
	]);
	const fieldMetadata = resolveFieldMetadata(taxInformationDefaultFieldConfig[country], {
		taxIdNumberType: currentCountryTaxInformation?.type,
		companyType: entityType
	}, taxInformationDefaultFieldMetadata);
	const updateTaxInfo = useCallback$1((mode, newEntry) => {
		const entry = canSaveAbsentState ? {
			...newEntry,
			numberAbsent: newEntry.numberAbsent ?? false
		} : newEntry;
		handleChangeFor("taxInformation", mode)(upsertTaxInfoForCountry(data.taxInformation, country, entry));
	}, [
		canSaveAbsentState,
		country,
		data.taxInformation,
		handleChangeFor
	]);
	const updateTaxType = useCallback$1((type, mode) => {
		updateTaxInfo(mode, {
			country,
			number: currentCountryTaxInformation?.number,
			type
		});
	}, [
		country,
		currentCountryTaxInformation?.number,
		updateTaxInfo
	]);
	const resetToDefaultData = useCallback$1(() => {
		if (defaultData !== void 0) handleChangeFor("taxInformation", "input")(defaultData);
	}, [defaultData, handleChangeFor]);
	const removeCountryTaxInfo = useCallback$1(() => {
		handleChangeFor("taxInformation", "input")(removeTaxInfoForCountry(data.taxInformation, country));
	}, [
		country,
		data.taxInformation,
		handleChangeFor
	]);
	const setUenAsTaxId = useCallback$1((uen) => {
		updateTaxInfo("blur", {
			country,
			number: uen ?? "",
			type: "UEN"
		});
	}, [country, updateTaxInfo]);
	const addTaxAbsentStatus = useCallback$1((exempted) => {
		handleChangeFor("taxInformation", "input")(upsertTaxInfoForCountry(data.taxInformation, country, {
			country,
			numberAbsent: exempted
		}));
	}, [
		country,
		data.taxInformation,
		handleChangeFor
	]);
	const handleTaxNumberChange = useCallback$1((e, mode) => {
		updateTaxInfo(mode, {
			country,
			number: e ? typeof e === "string" ? e : e.currentTarget.value : void 0,
			type: currentCountryTaxInformation?.type ?? (taxIdNumberType !== "exempted" ? taxIdNumberType : void 0)
		});
	}, [
		country,
		currentCountryTaxInformation?.type,
		taxIdNumberType,
		updateTaxInfo
	]);
	const handleTaxIdNumberTypeChange = useCallback$1((taxIdType) => {
		if (!canExempt && taxIdType === "exempted") throw Error(`${country} does not allow tax exemptions`);
		if (taxIdType === "exempted") {
			handleChangeFor("exemptedFromTax")(true);
			updateTaxType(void 0, "input");
			return canSaveAbsentState ? addTaxAbsentStatus(true) : removeCountryTaxInfo();
		}
		handleChangeFor("exemptedFromTax")(false);
		if (country === "SG") if (taxIdType === "UEN") {
			handleChangeFor("isUen")(true);
			setUenAsTaxId(registrationNumber);
		} else {
			handleChangeFor("isUen")(false);
			removeCountryTaxInfo();
		}
		updateTaxType(taxIdType, "input");
	}, [
		addTaxAbsentStatus,
		canExempt,
		canSaveAbsentState,
		country,
		handleChangeFor,
		updateTaxType,
		registrationNumber,
		removeCountryTaxInfo,
		setUenAsTaxId
	]);
	const handleExemptedFromTaxChange = useCallback$1((exempted) => {
		handleChangeFor("exemptedFromTax")(exempted);
		if (canSaveAbsentState) addTaxAbsentStatus(exempted);
		else removeCountryTaxInfo();
	}, [
		addTaxAbsentStatus,
		canSaveAbsentState,
		handleChangeFor,
		removeCountryTaxInfo
	]);
	const prevCountryRef = useRef$1(country);
	useEffect$1(() => {
		if (!country || prevCountryRef.current === country) return;
		prevCountryRef.current = country;
		const hasSavedTaxId = defaultData?.find((taxId) => taxId.country === country);
		if (currentCountryTaxInformation && !hasSavedTaxId) return;
		if (entityType === CompanyTypesValues.SOLE_PROPRIETORSHIP) return;
		resetToDefaultData();
	}, [country]);
	useEffect$1(() => {
		if (country === "SG" && data.isUen && registrationNumber && registrationNumber !== currentCountryTaxInformation?.number) setUenAsTaxId(registrationNumber);
	}, [
		registrationNumber,
		currentCountryTaxInformation?.number,
		data.isUen,
		country,
		setUenAsTaxId
	]);
	const isInitialized = useRef$1(false);
	if (!isInitialized.current && country === "SG" && !defaultData?.find((taxInfo) => taxInfo.country === country)?.number) {
		isInitialized.current = true;
		handleChangeFor("isUen")(false);
	}
	return /* @__PURE__ */ jsxs("div", { children: [
		/* @__PURE__ */ jsx(TaxIdNumberTypeSelector, {
			country,
			companyType: entityType,
			invertCompanyTypeFilter,
			setSelected: handleTaxIdNumberTypeChange,
			selected: taxIdNumberType,
			exemptedOptionLabel: showTaxIdExemptedOptions ? exemptionLabel : void 0,
			isUsSoleProp,
			errorMessage: isUsSoleProp ? errors.taxInformation : false
		}),
		shouldRenderInput && /* @__PURE__ */ jsx(MaskedInput, {
			type: "text",
			"aria-required": true,
			"aria-invalid": !valid.taxInformation,
			name: "taxInformation",
			label: labels.taxInformation ?? "",
			formatGuidance: translateTranslatable(t, fieldMetadata.guidanceText),
			value: currentCountryTaxInformation?.number ?? "",
			errorMessage: errors.taxInformation,
			placeholder,
			isValid: Boolean(valid.taxInformation) && !!currentCountryTaxInformation,
			onInput: (e) => handleTaxNumberChange(e, "input"),
			onBlur: (e) => handleTaxNumberChange(e, "blur"),
			disabled: data.exemptedFromTax || data.isUen,
			readonly,
			optional,
			shouldValidate,
			...mask
		}),
		canExempt && !showTaxIdExemptedOptions && /* @__PURE__ */ jsx(Field, {
			name: "exemptedFromTax",
			children: (childProps) => /* @__PURE__ */ jsx(Checkbox, {
				...childProps,
				"aria-required": false,
				"aria-invalid": false,
				name: "exemptedFromTax",
				label: labels.exemptedFromTax,
				value: "exemptedFromTax",
				checked: Boolean(data.exemptedFromTax),
				onChange: handleExemptedFromTaxChange
			})
		})
	] });
}
//#endregion
export { getFieldsWithExistingData as a, DocumentGuidance as i, TaxInformationField as n, MemoizedDocumentUpload as r, TAX_INFORMATION_FIELD as t };
