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] = "bcfcd66a-71ec-4d21-94c6-7c99a7e857cd", e._sentryDebugIdIdentifier = "sentry-dbid-bcfcd66a-71ec-4d21-94c6-7c99a7e857cd");
} catch (e) {}
import { r as useTranslation } from "./translation-Br5wIPO-.js";
import { n as IconButton, r as Loader, t as Button } from "./Button-BDEdGXnd.js";
import { n as httpGet, s as useApiContext } from "./http-CHTzpXCd.js";
import { t as useToggleContext } from "./useToggleContext-CLfowItk.js";
import { t as StackLayout } from "./StackLayout-BMQXXBDb.js";
import { i as TaskStatuses } from "./taskStatus-CvMqhrOK.js";
import { t as Header } from "./Header-B_MIsVov.js";
import { a as setNestedValue, i as resolveComponentProps, r as getNestedValue$3, t as TaskListItem } from "./TaskListItem-BM3oukq_.js";
import { t as useBusinessLines } from "./useBusinessLines-BJV9biUj.js";
import { t as CompanyTypesValues } from "./company-types-value-B-nraMaa.js";
import { t as EndStateLayout } from "./EndStateLayout-DxdIVWL3.js";
import { t as KEYBOARD_KEYS } from "./keys-C4gD4IDn.js";
import { t as Modal } from "./Modal-DOC6JgPI.js";
import { t as Confirm } from "./Confirm-BqhBxIWm.js";
import { n as translateTranslatable } from "./utils-g_Wl4-9Z.js";
import { t as useUpdateLegalEntity } from "./useUpdateLegalEntity-CUs6TYPF.js";
import { a as FormFlow_module_default } from "./useFormContext-Cu4dKSCy.js";
import { t as List } from "./List-DLrcpMVd.js";
import { t as MaskedInput } from "./MaskedInput-uN8G9HRq.js";
import { t as ProgressBar } from "./ProgressBar-DrvdkkV2.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 InputText } from "./InputText-CadVntiC.js";
import { t as AcceptTermsOfServiceComponent } from "./AcceptTermsOfServiceComponent-BIYgOoqa.js";
import { t as Divider } from "./Divider-DHTBXv3p.js";
import { t as DecisionMakers } from "./DecisionMakers-c0L12DVq.js";
import { i as getCompanyRegistrationNumberOptions, l as registrationNumberDefaultFieldConfig, n as getDefaultRegistrationNumberType, t as CompanyRegistrationNumberTypeSelector, u as registrationNumberDefaultFieldMetadata } from "./CompanyRegistrationNumberTypeSelector-CeRtLSxc.js";
import { n as useCreateBusinessLine, r as useIndustryCodes, t as useUpdateBusinessLine } from "./useUpdateBusinessLines-BUFe2lBW.js";
import { t as SourceOfFundsPage } from "./SourceOfFundsPage-GTMmyUv0.js";
import { t as TaxReportingDropin } from "./TaxReportingDropin-BMYbiHlX.js";
import { useCallback, useContext, useEffect, useMemo, useRef, useState } from "preact/hooks";
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
import { useComputed } from "@preact/signals";
import { useQuery } from "@tanstack/preact-query";
import { createContext } from "preact";
import { createFormHook, createFormHookContexts, useStore } from "@tanstack/react-form";
//#region src/api/adaptive/useAdaptiveWorkflow.ts
/**
* Retrieves UI manifest used to render an adaptive UI
* determined by the requirements engine based on the
* requested products for a LE
*/
var getUiManifest = async (baseUrl, rootLegalEntityId) => {
	return await httpGet({
		baseUrl,
		path: `legalEntities/${rootLegalEntityId}/configurations/workflow`
	});
};
var useAdaptiveWorkflow = (options) => {
	const { baseUrl, rootLegalEntityId } = useApiContext();
	return useQuery({
		queryKey: ["adaptive-workflow"],
		queryFn: () => getUiManifest(baseUrl.value, rootLegalEntityId.value),
		...options
	});
};
//#endregion
//#region src/context/WorkflowContext/WorkflowContext.tsx
var WorkflowContext = createContext(void 0);
//#endregion
//#region src/context/WorkflowContext/useWorkflowContext.ts
function useWorkflowContext() {
	return useContext(WorkflowContext);
}
var AdaptiveWorkflow_module_default = {
	"adaptive-workflow-header": "adyen-kyc-adaptive-workflow-header",
	adaptiveWorkflowHeader: "adyen-kyc-adaptive-workflow-header",
	"adaptive-workflow-main": "adyen-kyc-adaptive-workflow-main",
	adaptiveWorkflowMain: "adyen-kyc-adaptive-workflow-main",
	"adaptive-workflow-heading": "adyen-kyc-adaptive-workflow-heading",
	adaptiveWorkflowHeading: "adyen-kyc-adaptive-workflow-heading",
	"adaptive-workflow-description": "adyen-kyc-adaptive-workflow-description",
	adaptiveWorkflowDescription: "adyen-kyc-adaptive-workflow-description",
	"adaptive-workflow-divider": "adyen-kyc-adaptive-workflow-divider",
	adaptiveWorkflowDivider: "adyen-kyc-adaptive-workflow-divider",
	"adaptive-workflow-actions": "adyen-kyc-adaptive-workflow-actions",
	adaptiveWorkflowActions: "adyen-kyc-adaptive-workflow-actions"
};
//#endregion
//#region src/adaptiveWorkflow/components/Fields/AcceptTermsOfServiceWorkflow/AcceptTermsOfServiceWorkflow.tsx
var AcceptTermsOfServiceWorkflow = ({ onComplete, onClose, resourceId }) => {
	if (!resourceId) return /* @__PURE__ */ jsx(EndStateLayout, {
		variant: "error",
		title: "Something went wrong",
		description: "Please try again later"
	});
	return /* @__PURE__ */ jsx(AcceptTermsOfServiceComponent, {
		legalEntityId: resourceId,
		onComplete,
		onClose
	});
};
//#endregion
//#region src/adaptiveWorkflow/formHook.ts
var { fieldContext, formContext } = createFormHookContexts();
/**
* Shared form hook for the adaptive workflow.
*
* - `useAppForm` replaces `useForm` and provides context-aware form instances.
* - `withForm` wraps compound components so they receive `form` via context,
*    eliminating the need to pass the form instance (and its complex generics) as a prop.
*
* @see https://tanstack.com/form/latest/docs/framework/react/guides/form-composition
*/
var { useAppForm, withForm } = createFormHook({
	fieldContext,
	formContext,
	fieldComponents: {},
	formComponents: {}
});
//#endregion
//#region src/adaptiveWorkflow/components/Fields/BusinessRegistrationNumber/ExemptedFromRegistrationNumberField.tsx
function ExemptedFromRegistrationNumberField({ field, label, checked, readonly, onChange }) {
	return /* @__PURE__ */ jsx(Field, {
		name: field.name,
		children: (childProps) => /* @__PURE__ */ jsx(Checkbox, {
			...childProps,
			"aria-required": false,
			"aria-invalid": false,
			name: field.name,
			label,
			value: "exemptedFromRegistrationNumber",
			checked,
			readonly,
			onChange
		})
	});
}
//#endregion
//#region src/adaptiveWorkflow/components/Fields/BusinessRegistrationNumber/RegistrationNumberInputField.tsx
function RegistrationNumberInputField({ field, fieldMetadata, currentValue, helperText, readonly, optional, shouldValidate, disabled, onInput, onBlur }) {
	const { t } = useTranslation("common");
	const isTouched = field.state.meta.isTouched;
	const isValid = field.state.meta.isValid;
	const errorMessage = isTouched && !isValid ? field.state.meta.errors[0] : void 0;
	return /* @__PURE__ */ jsx(MaskedInput, {
		"aria-required": true,
		"aria-invalid": isTouched && !isValid,
		name: "registrationNumber",
		type: "text",
		value: currentValue,
		label: fieldMetadata.label ? t(($) => $[fieldMetadata.label]) ?? "" : "",
		formatGuidance: fieldMetadata.guidanceText ? translateTranslatable(t, fieldMetadata.guidanceText) : void 0,
		errorMessage,
		isValid: isTouched && isValid && !!currentValue,
		onInput,
		onBlur,
		disabled,
		optional,
		readonly,
		shouldValidate: !optional && shouldValidate,
		helper: helperText,
		...fieldMetadata.mask ?? {}
	});
}
//#endregion
//#region src/adaptiveWorkflow/components/Fields/BusinessRegistrationNumber/RegistrationNumberTypeSelectorField.tsx
function RegistrationNumberTypeSelectorField({ country, companyType, invertCompanyTypeFilter, selected, onTypeChange, exemptedOptionLabel }) {
	return /* @__PURE__ */ jsx(CompanyRegistrationNumberTypeSelector, {
		country,
		companyType,
		invertCompanyTypeFilter,
		selected,
		setSelected: onTypeChange,
		exemptedOptionLabel
	});
}
//#endregion
//#region src/adaptiveWorkflow/components/Fields/BusinessRegistrationNumber/BusinessRegistrationNumberFieldGroup.tsx
function getNestedValue$2(obj, path) {
	return path.split(".").reduce((acc, key) => acc?.[key], obj);
}
var BusinessRegistrationNumberFieldGroup = withForm({
	defaultValues: {},
	props: {},
	render: function BusinessRegistrationNumberFieldGroupRender({ form, basePath: registrationNumberPath, country, canExempt, companyType, state, helperText, invertCompanyTypeFilter, labels, readonly, optional, shouldValidate }) {
		const registrationNumberTypePath = `organization.registrationNumberType`;
		const exemptedPath = `organization.exemptedFromRegistrationNumber`;
		const registrationNumber = useStore(form.store, (s) => getNestedValue$2(s.values, registrationNumberPath));
		const registrationNumberType = useStore(form.store, (s) => getNestedValue$2(s.values, registrationNumberTypePath));
		const exemptedFromRegistrationNumber = useStore(form.store, (s) => getNestedValue$2(s.values, exemptedPath));
		const registrationNumberOptions = getCompanyRegistrationNumberOptions(country, companyType, invertCompanyTypeFilter);
		const defaultType = getDefaultRegistrationNumberType(registrationNumber, country, companyType, invertCompanyTypeFilter);
		const showExemptedOption = canExempt && !!registrationNumberOptions && registrationNumberOptions.length > 1;
		const effectiveRegistrationNumberType = exemptedFromRegistrationNumber ? "exempted" : registrationNumberType ?? defaultType;
		const fieldMetadata = resolveFieldMetadata(registrationNumberDefaultFieldConfig[country], {
			registrationNumberType: effectiveRegistrationNumberType === "exempted" ? void 0 : effectiveRegistrationNumberType,
			state
		}, registrationNumberDefaultFieldMetadata);
		if (effectiveRegistrationNumberType && effectiveRegistrationNumberType !== "exempted" && !registrationNumberOptions?.find((o) => o.id === effectiveRegistrationNumberType)) form.setFieldValue(registrationNumberTypePath, defaultType);
		const handleRegistrationNumberChange = useCallback((e) => {
			const value = typeof e === "string" ? e : e.currentTarget.value;
			form.setFieldValue(registrationNumberPath, value);
			form.setFieldValue(registrationNumberTypePath, effectiveRegistrationNumberType === "exempted" ? void 0 : effectiveRegistrationNumberType);
		}, [
			form,
			registrationNumberPath,
			registrationNumberTypePath,
			effectiveRegistrationNumberType
		]);
		const handleExemptedFromRegistrationNumber = useCallback((exempt) => {
			if (exempt) form.setFieldValue(registrationNumberPath, "");
			form.setFieldValue(exemptedPath, exempt);
		}, [
			exemptedPath,
			form,
			registrationNumberPath
		]);
		const handleCompanyRegistrationNumberTypeChange = useCallback((regNumberType) => {
			if (regNumberType === "exempted") {
				if (!canExempt) throw new Error(`${country} does not allow registration number exemptions`);
				form.setFieldValue(registrationNumberPath, "");
				form.setFieldValue(exemptedPath, true);
				form.setFieldValue(registrationNumberTypePath, void 0);
				return;
			}
			if (canExempt && exemptedFromRegistrationNumber) form.setFieldValue(exemptedPath, false);
			form.setFieldValue(registrationNumberPath, "");
			form.setFieldValue(registrationNumberTypePath, regNumberType);
		}, [
			canExempt,
			country,
			exemptedFromRegistrationNumber,
			exemptedPath,
			form,
			registrationNumberPath,
			registrationNumberTypePath
		]);
		return /* @__PURE__ */ jsxs("div", { children: [
			/* @__PURE__ */ jsx(form.Field, {
				name: registrationNumberTypePath,
				children: (field) => /* @__PURE__ */ jsx(RegistrationNumberTypeSelectorField, {
					field,
					country,
					companyType,
					invertCompanyTypeFilter,
					selected: effectiveRegistrationNumberType,
					onTypeChange: handleCompanyRegistrationNumberTypeChange,
					exemptedOptionLabel: showExemptedOption ? labels.exemptedFromRegistrationNumber : void 0
				})
			}),
			/* @__PURE__ */ jsx(form.Field, {
				name: registrationNumberPath,
				children: (field) => /* @__PURE__ */ jsx(RegistrationNumberInputField, {
					field,
					fieldMetadata,
					currentValue: registrationNumber ?? "",
					helperText,
					readonly,
					optional,
					shouldValidate,
					disabled: Boolean(exemptedFromRegistrationNumber),
					onInput: (e) => handleRegistrationNumberChange(e),
					onBlur: (e) => handleRegistrationNumberChange(e)
				})
			}),
			canExempt && !showExemptedOption && /* @__PURE__ */ jsx(form.Field, {
				name: exemptedPath,
				children: (field) => /* @__PURE__ */ jsx(ExemptedFromRegistrationNumberField, {
					field,
					label: labels.exemptedFromRegistrationNumber,
					checked: Boolean(exemptedFromRegistrationNumber),
					readonly,
					onChange: handleExemptedFromRegistrationNumber
				})
			})
		] });
	}
});
//#endregion
//#region src/adaptiveWorkflow/components/Fields/IndustryCode/IndustryCodeFieldGroup.tsx
function mapSelectedCodes(selectedCodes) {
	return selectedCodes && selectedCodes.length > 0 ? selectedCodes.map((i) => ({
		value: i,
		touched: !!i.id
	})) : [{
		value: {
			id: "",
			name: ""
		},
		touched: false
	}];
}
function getNestedValue$1(obj, path) {
	return path.split(".").reduce((acc, key) => acc?.[key], obj);
}
var IndustryCodeFieldGroup = withForm({
	defaultValues: {},
	props: {},
	render: function IndustryCodeFieldGroupRender({ form, basePath: industryCodesPath, businessLineTypes, single = true }) {
		const { t, i18n } = useTranslation(["common", "ui"]);
		const { isFeatureEnabled } = useToggleContext();
		const { data: industryCodes, isLoading: industryCodesLoading } = useIndustryCodes(businessLineTypes, i18n.language);
		const { data: existingBusinessLines, isLoading: existingBusinessLinesLoading } = useBusinessLines(["banking"]);
		const selectedCodes = useStore(form.store, (s) => getNestedValue$1(s.values, industryCodesPath));
		const [items, setItems] = useState(() => mapSelectedCodes(selectedCodes));
		const containerRef = useRef(null);
		const singleIndustryCode = single || isFeatureEnabled("EnableLimitToSingleBusinessLine");
		const allIndustryCodeSelectItems = useMemo(() => industryCodes?.map((entry) => ({
			id: entry.code,
			name: `${entry.code} - ${entry.description}`
		})) ?? [], [industryCodes]);
		const selectableIndustryCodes = useMemo(() => {
			if (!businessLineTypes.includes("acquiring")) return allIndustryCodeSelectItems;
			const selectedIds = selectedCodes?.map((c) => c.id);
			const existingIds = (existingBusinessLines ?? []).map((b) => b.industryCode);
			return allIndustryCodeSelectItems.filter(({ id }) => {
				return !selectedIds?.includes(id) && !existingIds?.includes(id);
			});
		}, [
			allIndustryCodeSelectItems,
			businessLineTypes,
			selectedCodes,
			existingBusinessLines
		]);
		const updateFormValues = (newItems) => {
			form.setFieldValue(industryCodesPath, newItems.map(({ value }) => value));
		};
		const handleSelectIndustryCode = (indexToUpdate, selectedItem) => {
			setItems((prevItems) => {
				const newItems = prevItems.map((item, i) => i === indexToUpdate ? {
					value: {
						id: selectedItem.id,
						name: selectedItem.name
					},
					touched: true
				} : item);
				updateFormValues(newItems);
				return newItems;
			});
		};
		const addIndustryCodeField = (e) => {
			if (items[items.length - 1].value.id === "") {
				handleContainerBlur(e, items.length - 1);
				return;
			}
			const newItems = [...items, {
				value: {
					id: "",
					name: ""
				},
				touched: false
			}];
			setItems(newItems);
			updateFormValues(newItems);
		};
		const removeField = (indexToRemove) => {
			const newItems = items.filter((_, i) => i !== indexToRemove);
			setItems(newItems);
			updateFormValues(newItems);
		};
		const handleContainerBlur = (e, index) => {
			if (containerRef.current && !containerRef.current.contains(e.relatedTarget)) setItems((prevItems) => {
				if (prevItems[index].value.id || prevItems[index].touched) return prevItems;
				const newItems = [...prevItems];
				newItems[index] = {
					...newItems[index],
					touched: true
				};
				return newItems;
			});
		};
		return /* @__PURE__ */ jsx(form.Field, {
			name: industryCodesPath,
			validators: { onBlur: ({ value }) => {
				const codes = value;
				return !codes?.length || codes.some((c) => !c.id) ? "fieldIsRequired" : void 0;
			} },
			children: (field) => {
				if (industryCodesLoading || existingBusinessLinesLoading) return /* @__PURE__ */ jsx(Loader, { size: "large" });
				const isTouched = field.state.meta.isTouched;
				const isValid = field.state.meta.isValid;
				const errorMessage = isTouched && !isValid ? field.state.meta.errors[0] : void 0;
				return /* @__PURE__ */ jsx(Field, {
					name: "industryCodes",
					label: t(($) => $["industry"], { ns: "ui" }),
					errorMessage,
					isValid: isTouched && isValid,
					showErrorIcon: false,
					children: (childProps) => {
						const content = /* @__PURE__ */ jsx("div", {
							ref: containerRef,
							"data-testid": "industryCode",
							style: {
								display: "flex",
								flexDirection: "column",
								gap: "8px"
							},
							children: items.map((code, index) => {
								const isInvalid = code.touched && code.value.id === "";
								return /* @__PURE__ */ jsxs("div", {
									style: {
										display: "flex",
										alignItems: "center",
										gap: "8px"
									},
									children: [/* @__PURE__ */ jsx(Select, {
										...childProps,
										id: `industryCodeSelection-${index}`,
										name: `industryCodeSelection-${index}`,
										selected: code.value,
										placeholder: t(($) => $["industryCode__placeholder"], { ns: "ui" }),
										items: allIndustryCodeSelectItems,
										excludedValues: allIndustryCodeSelectItems.filter((i) => !selectableIndustryCodes.includes(i)),
										readonly: !!industryCodes && selectableIndustryCodes.length === 0,
										onSelect: (selectedItem) => handleSelectIndustryCode(index, selectedItem),
										isInvalid,
										onBlur: (e) => {
											handleContainerBlur(e, index);
											field.handleBlur();
										}
									}), !singleIndustryCode && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(IconButton, {
										ariaLabel: t(($) => $["removeIndustryCode"], { ns: "ui" }),
										variant: "tertiary",
										icon: "minusCircleFilled",
										circle: true,
										onClick: () => removeField(index),
										disabled: items.length === 1
									}), /* @__PURE__ */ jsx(IconButton, {
										ariaLabel: t(($) => $["addIndustryCode"], { ns: "ui" }),
										variant: "tertiary",
										icon: "plusCircleFilled",
										circle: true,
										onClick: addIndustryCodeField,
										disabled: code.value.id === "" || code.value.id !== "" && index !== items.length - 1 || selectableIndustryCodes.length === 0
									})] })]
								}, `${code.value.id}-${index}`);
							})
						});
						return singleIndustryCode ? content : /* @__PURE__ */ jsx(List, {
							dividers: false,
							variant: "grouped-primary",
							children: content
						});
					}
				});
			}
		});
	}
});
//#endregion
//#region src/adaptiveWorkflow/components/Fields/LegalName.tsx
function LegalName({ name, data, valid, errors, labels, helperText, readonly, handleChangeFor }) {
	const handleKeyDown = (e) => {
		if (e.key === KEYBOARD_KEYS.enter) e.preventDefault();
	};
	return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", { children: name }), /* @__PURE__ */ jsx(Field, {
		name,
		label: labels,
		helper: helperText,
		errorMessage: errors,
		isValid: valid,
		children: (_childProps) => /* @__PURE__ */ jsx(InputText, {
			"aria-required": true,
			"aria-invalid": !valid,
			name,
			value: data,
			readonly,
			onInput: handleChangeFor,
			onBlur: handleChangeFor,
			onKeyDown: handleKeyDown
		})
	})] });
}
//#endregion
//#region src/adaptiveWorkflow/components/Fields/SourceOfFundsWorkflow/SourceOfFundsWorkflow.tsx
var SourceOfFundsWorkflow = ({ onComplete, onClose, resourceId }) => {
	if (!resourceId) return /* @__PURE__ */ jsx(EndStateLayout, {
		variant: "error",
		title: "Something went wrong",
		description: "Please try again later"
	});
	return /* @__PURE__ */ jsx(SourceOfFundsPage, {
		onSubmit: onComplete,
		handleHomeClick: onClose,
		asAwe: true
	});
};
//#endregion
//#region src/adaptiveWorkflow/components/Fields/TaxInformation/ExemptedFromTaxField.tsx
function ExemptedFromTaxField({ field, label, checked, onChange }) {
	return /* @__PURE__ */ jsx(Field, {
		name: field.name,
		children: (childProps) => /* @__PURE__ */ jsx(Checkbox, {
			...childProps,
			"aria-required": false,
			"aria-invalid": false,
			name: field.name,
			label,
			value: "exemptedFromTax",
			checked,
			onChange
		})
	});
}
//#endregion
//#region src/adaptiveWorkflow/components/Fields/TaxInformation/TaxIdNumberInputField.tsx
function TaxIdNumberInputField({ field, fieldMetadata, currentValue, placeholder, readonly, optional, shouldValidate, disabled, onInput, onBlur }) {
	const { t } = useTranslation("common");
	const isTouched = field.state.meta.isTouched;
	const isValid = field.state.meta.isValid;
	const errorMessage = isTouched && !isValid ? field.state.meta.errors[0] : void 0;
	return /* @__PURE__ */ jsx(MaskedInput, {
		type: "text",
		"aria-required": true,
		"aria-invalid": isTouched && !isValid,
		name: "taxInformation",
		label: fieldMetadata.label ? t(($) => $[fieldMetadata.label]) ?? "" : "",
		formatGuidance: fieldMetadata.guidanceText ? translateTranslatable(t, fieldMetadata.guidanceText) : void 0,
		value: currentValue,
		errorMessage,
		placeholder,
		isValid: isValid && !!currentValue,
		onInput,
		onBlur,
		disabled,
		readonly,
		optional,
		shouldValidate,
		...fieldMetadata.mask ?? {}
	});
}
//#endregion
//#region src/adaptiveWorkflow/components/Fields/TaxInformation/TaxIdTypeSelectorField.tsx
function TaxIdTypeSelectorField({ field, country, companyType, selected, onTypeChange, exemptedOptionLabel, isUsSoleProp }) {
	const errorMessage = field.state.meta.isTouched && !field.state.meta.isValid ? field.state.meta.errors[0] : void 0;
	return /* @__PURE__ */ jsx(TaxIdNumberTypeSelector, {
		country,
		companyType,
		selected,
		setSelected: onTypeChange,
		exemptedOptionLabel,
		isUsSoleProp,
		errorMessage: isUsSoleProp ? errorMessage : void 0
	});
}
//#endregion
//#region src/adaptiveWorkflow/components/Fields/TaxInformation/TaxInformationFieldGroup.tsx
function getNestedValue(obj, path) {
	return path.split(".").reduce((acc, key) => acc?.[key], obj);
}
var TaxInformationFieldGroup = withForm({
	defaultValues: {},
	props: {},
	render: function TaxInformationFieldGroupRender({ form, basePath: taxInfoPath, country, canExempt, entityType, registrationNumber, defaultData, labels, placeholder, readonly, optional }) {
		const { isFeatureEnabled } = useToggleContext();
		const { t } = useTranslation("common");
		const taxNumberPath = `${taxInfoPath}.number`;
		const taxTypePath = `${taxInfoPath}.type`;
		const exemptedPath = `${taxInfoPath}.numberAbsent`;
		const isUenPath = `${taxInfoPath}.isUen`;
		const taxInformations = useStore(form.store, (s) => getNestedValue(s.values, taxInfoPath));
		const exemptedFromTax = useStore(form.store, (s) => getNestedValue(s.values, exemptedPath));
		const isUsSoleProp = country === "US" && entityType === CompanyTypesValues.SOLE_PROPRIETORSHIP;
		const currentTaxInformation = useMemo(() => taxInformations?.find((t) => t.country === country), [taxInformations, country]);
		const taxIdNumberType = useMemo(() => {
			if (currentTaxInformation?.numberAbsent) return "exempted";
			if (currentTaxInformation?.type) return currentTaxInformation.type;
			if (isUsSoleProp) return void 0;
			return getDefaultTaxIdNumberType(taxInformations, country, entityType);
		}, [
			currentTaxInformation?.type,
			currentTaxInformation?.numberAbsent,
			taxInformations,
			isUsSoleProp,
			country,
			entityType
		]);
		const options = getTaxIdNumberOptions(country, entityType);
		const showTaxIdExemptedOptions = canExempt && (options?.length ?? 0) > 1 || isUsSoleProp;
		const canSaveAbsentState = isFeatureEnabled("EnableRegistrationAndTaxAbsentStatesV4") && COUNTRIES_WITH_POSSIBLE_TRUSTEE_TAXID_ABSENT_V4.includes(country);
		const fieldMetadata = resolveFieldMetadata(taxInformationDefaultFieldConfig[country], {
			taxIdNumberType: currentTaxInformation?.type,
			companyType: entityType
		}, taxInformationDefaultFieldMetadata);
		const exemptionLabel = isUsSoleProp ? t(($) => $["socialSecurityNumber"]) : labels?.exemptedFromTax;
		const updateTaxInfo = useCallback((mode, newEntry) => {
			const updated = upsertTaxInfoForCountry(defaultData, country, canSaveAbsentState ? {
				...newEntry,
				numberAbsent: newEntry.numberAbsent ?? false
			} : newEntry);
			form.setFieldValue(taxInfoPath, updated);
		}, [
			canSaveAbsentState,
			country,
			form,
			taxInfoPath,
			defaultData
		]);
		const updateTaxType = useCallback((type, mode) => {
			updateTaxInfo(mode, {
				country,
				number: currentTaxInformation?.number,
				type
			});
		}, [
			country,
			currentTaxInformation?.number,
			updateTaxInfo
		]);
		const removeCountryTaxInfo = useCallback(() => {
			form.setFieldValue(taxInfoPath, removeTaxInfoForCountry(taxInformations, country));
		}, [
			country,
			form,
			taxInfoPath,
			taxInformations
		]);
		const addTaxAbsentStatus = useCallback((absent) => {
			form.setFieldValue(taxInfoPath, upsertTaxInfoForCountry(taxInformations, country, {
				country,
				numberAbsent: absent
			}));
		}, [
			country,
			form,
			taxInfoPath,
			taxInformations
		]);
		const setUenAsTaxId = useCallback((uen) => {
			updateTaxInfo("blur", {
				country,
				number: uen ?? "",
				type: "UEN"
			});
		}, [country, updateTaxInfo]);
		const resetToDefaultData = useCallback(() => {
			if (defaultData !== void 0) form.setFieldValue(taxInfoPath, defaultData);
		}, [
			defaultData,
			form,
			taxInfoPath
		]);
		const handleTaxIdNumberTypeChange = useCallback((taxIdType) => {
			if (!canExempt && taxIdType === "exempted") throw new Error(`${country} does not allow tax exemptions`);
			if (taxIdType === "exempted") {
				form.setFieldValue(exemptedPath, true);
				updateTaxType(void 0, "input");
				return canSaveAbsentState ? addTaxAbsentStatus(true) : removeCountryTaxInfo();
			}
			form.setFieldValue(exemptedPath, false);
			if (country === "SG") if (taxIdType === "UEN") {
				form.setFieldValue(isUenPath, true);
				setUenAsTaxId(registrationNumber);
			} else {
				form.setFieldValue(isUenPath, false);
				removeCountryTaxInfo();
			}
			updateTaxType(taxIdType, "input");
		}, [
			addTaxAbsentStatus,
			canExempt,
			canSaveAbsentState,
			country,
			exemptedPath,
			form,
			isUenPath,
			removeCountryTaxInfo,
			registrationNumber,
			setUenAsTaxId,
			updateTaxType
		]);
		const handleTaxNumberChange = useCallback((e, mode) => {
			updateTaxInfo(mode, {
				country,
				number: e ? typeof e === "string" ? e : e.currentTarget.value : void 0,
				type: currentTaxInformation?.type ?? (taxIdNumberType !== "exempted" ? taxIdNumberType : void 0)
			});
		}, [
			country,
			currentTaxInformation?.type,
			taxIdNumberType,
			updateTaxInfo
		]);
		const handleExemptedFromTaxChange = useCallback((exempted) => {
			form.setFieldValue(exemptedPath, exempted);
			if (canSaveAbsentState) addTaxAbsentStatus(exempted);
			else removeCountryTaxInfo();
		}, [
			addTaxAbsentStatus,
			canSaveAbsentState,
			exemptedPath,
			form,
			removeCountryTaxInfo
		]);
		const prevCountryRef = useRef(country);
		useEffect(() => {
			if (!country || prevCountryRef.current === country) return;
			prevCountryRef.current = country;
			const hasSavedTaxId = defaultData?.find((t) => t.country === country);
			if (currentTaxInformation && !hasSavedTaxId) return;
			if (entityType === CompanyTypesValues.SOLE_PROPRIETORSHIP) return;
			resetToDefaultData();
		}, [
			country,
			currentTaxInformation,
			defaultData,
			entityType,
			resetToDefaultData
		]);
		useEffect(() => {
			if (country === "SG" && registrationNumber && registrationNumber !== currentTaxInformation?.number) setUenAsTaxId(registrationNumber);
		}, [
			registrationNumber,
			currentTaxInformation?.number,
			country,
			setUenAsTaxId
		]);
		return /* @__PURE__ */ jsxs("div", { children: [
			/* @__PURE__ */ jsx(form.Field, {
				name: taxTypePath,
				children: (field) => /* @__PURE__ */ jsx(TaxIdTypeSelectorField, {
					field,
					country,
					companyType: entityType,
					selected: taxIdNumberType,
					onTypeChange: handleTaxIdNumberTypeChange,
					exemptedOptionLabel: showTaxIdExemptedOptions ? exemptionLabel : void 0,
					isUsSoleProp
				})
			}),
			/* @__PURE__ */ jsx(form.Field, {
				name: taxNumberPath,
				children: (field) => /* @__PURE__ */ jsx(TaxIdNumberInputField, {
					field,
					fieldMetadata,
					currentValue: currentTaxInformation?.number ?? "",
					placeholder,
					readonly,
					optional,
					shouldValidate: true,
					disabled: Boolean(exemptedFromTax),
					onInput: (e) => handleTaxNumberChange(e, "input"),
					onBlur: (e) => handleTaxNumberChange(e, "blur")
				})
			}),
			canExempt && !showTaxIdExemptedOptions && /* @__PURE__ */ jsx(form.Field, {
				name: exemptedPath,
				children: (field) => /* @__PURE__ */ jsx(ExemptedFromTaxField, {
					field,
					label: labels?.exemptedFromTax,
					checked: Boolean(exemptedFromTax),
					onChange: handleExemptedFromTaxChange
				})
			})
		] });
	}
});
//#endregion
//#region src/adaptiveWorkflow/components/Fields/TaxReportingWorkflow/TaxReportingWorkflow.tsx
var TaxReportingWorkflow = ({ onComplete, onClose, resourceId }) => {
	if (!resourceId) return /* @__PURE__ */ jsx(EndStateLayout, {
		variant: "error",
		title: "Something went wrong",
		description: "Please try again later"
	});
	return /* @__PURE__ */ jsx(TaxReportingDropin, {
		onSubmit: onComplete,
		handleHomeClick: onClose,
		asAwe: true
	});
};
//#endregion
//#region src/adaptiveWorkflow/component-registry.ts
/**
* Registry for simple (single form.Field) components
*/
var simpleComponentMap = { LegalNameField: LegalName };
/**
* Registry for compound components
* Compound components receive form + basePath + dynamic server-driven props.
* The map value must be ComponentType<any> because each compound component has its own unique
* props interface — there's no single type that covers all of them in a dynamic registry.
*/
var compoundComponentMap = {
	TaxInformationFieldGroup,
	BusinessRegistrationNumberFieldGroup,
	IndustryCodeFieldGroup
};
/**
* Registry for specialized components
* Specialized components are intended to be all encompassing, handling their own
* field rendering, form steps (if applicable), data submission, etc.
*
* Naming convention: `${componentName}Workflow`
*/
var specializedComponentMap = {
	SourceOfFunds: SourceOfFundsWorkflow,
	IdentityScreening: DecisionMakers,
	TaxReporting: TaxReportingWorkflow,
	AcceptTermsOfService: AcceptTermsOfServiceWorkflow
};
//#endregion
//#region src/adaptiveWorkflow/components/DynamicForm/contextMap.ts
var contextMap$2 = {
	businessDetails: {
		heading: "businessInformation",
		description: "placeholder"
	},
	additionalBusinessDetails: {
		heading: "additionalBusinessDetails",
		description: "placeholder"
	}
};
//#endregion
//#region src/adaptiveWorkflow/components/DynamicForm/useCustomerData.ts
function mapFormValuesToPayload({ steps, globals, formValues }) {
	const components = steps.flatMap((step) => step.componentGroups.flatMap((group) => group.components));
	const domainPayloads = {};
	for (const component of components) {
		const dotIndex = component.path.indexOf(".");
		const domain = dotIndex !== -1 ? component.path.slice(0, dotIndex) : component.path;
		const subPath = dotIndex !== -1 ? component.path.slice(dotIndex + 1) : "";
		if (!domainPayloads[domain]) domainPayloads[domain] = {
			id: void 0,
			data: {}
		};
		const apiValue = getNestedValue$3(formValues, component.path);
		const resolvedProps = resolveComponentProps(globals.value, component.props);
		domainPayloads[domain].id = resolvedProps?.resourceId;
		if (subPath) setNestedValue(domainPayloads[domain].data, subPath, apiValue);
		else Object.assign(domainPayloads[domain].data, apiValue);
	}
	return domainPayloads;
}
async function doLegalEntityUpdates({ rootLegalEntityId, domainPayloads, updateLegalEntity }) {
	await updateLegalEntity.mutateAsync({
		...!!domainPayloads.organization?.data && {
			id: domainPayloads.organization.id ?? rootLegalEntityId.value,
			organization: domainPayloads.organization.data
		},
		...!!domainPayloads.individual?.data && {
			id: domainPayloads.individual.id ?? rootLegalEntityId.value,
			individual: domainPayloads.individual.data
		}
	});
}
async function doBusinessLineUpdates({ rootLegalEntityId, domainPayloads, createBusinessLine, updateBusinessLine }) {
	const businessLinePayload = domainPayloads.businessLine;
	if (!businessLinePayload?.data) return;
	const payload = {
		...businessLinePayload.data,
		id: businessLinePayload.id,
		legalEntityId: rootLegalEntityId.value
	};
	if (payload.id) return await updateBusinessLine.mutateAsync(payload);
	else return await createBusinessLine.mutateAsync(payload);
}
/**
* Routes DynamicForm submission to the correct API mutations based on the data path prefix
* declared in each `ComponentConfig`:
*
* - `organization.*` / `individual.*` → `useUpdateLegalEntity` (PATCH)
* - `businessLine.*`                  → `useCreateBusinessLine` (POST, no id) /
*                                       `useUpdateBusinessLine` (POST, with id)
*
* @param steps          - step config from the server response; used to enumerate data paths
*                         for current task
* @param legalEntityId  - override the legal entity ID for non-root entities (e.g. UBOs).
*                         Defaults to `rootLegalEntityId` from `ApiContext`.
*/
function useCustomerData(steps) {
	const { rootLegalEntityId } = useApiContext();
	const { globals, updateGlobals } = useWorkflowContext();
	const updateLegalEntity = useUpdateLegalEntity();
	const createBusinessLine = useCreateBusinessLine();
	const updateBusinessLine = useUpdateBusinessLine();
	return { submit: useCallback(async (formValues) => {
		const domainPayloads = mapFormValuesToPayload({
			steps,
			globals,
			formValues
		});
		await doLegalEntityUpdates({
			rootLegalEntityId,
			domainPayloads,
			updateLegalEntity
		});
		const businessLine = await doBusinessLineUpdates({
			rootLegalEntityId,
			domainPayloads,
			createBusinessLine,
			updateBusinessLine
		});
		updateGlobals({ ...businessLine?.id && { "businessLine.id": {
			type: "string",
			value: businessLine.id
		} } });
	}, [
		steps,
		rootLegalEntityId,
		createBusinessLine,
		globals,
		updateBusinessLine,
		updateGlobals,
		updateLegalEntity
	]) };
}
//#endregion
//#region src/adaptiveWorkflow/components/DynamicForm/DynamicForm.tsx
function renderSimpleField(componentName, field) {
	const FieldComponent = simpleComponentMap[componentName];
	if (FieldComponent) return /* @__PURE__ */ jsx(FieldComponent, {
		name: componentName,
		handleChangeFor: field.handleChange
	});
	return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("p", { children: componentName }), /* @__PURE__ */ jsx(InputText, {
		onInput: field.handleChange,
		onBlur: field.handleChange,
		name: componentName
	})] });
}
function renderCompoundField(compoundFieldProps) {
	const { componentName, form, basePath, props } = compoundFieldProps;
	const CompoundComponent = compoundComponentMap[componentName];
	if (CompoundComponent) return /* @__PURE__ */ jsx(CompoundComponent, {
		form,
		basePath,
		...props
	});
	return null;
}
function DynamicForm({ onClose, onComplete, steps }) {
	const { t } = useTranslation("adaptive");
	const { t: commonT } = useTranslation(["common"]);
	const { submit: submitCustomerData } = useCustomerData(steps);
	const { globals } = useWorkflowContext();
	const form = useAppForm({
		defaultValues: {},
		onSubmit: async ({ value }) => {
			await submitCustomerData(value);
			onComplete();
		}
	});
	const [currentStep, setCurrentStep] = useState(steps[0]);
	const [isConfirmPresented, setIsConfirmPresented] = useState(false);
	const currentStepIndex = steps.findIndex((step) => step.id === currentStep.id);
	const isFirstStep = currentStepIndex === 0;
	const isLastStep = currentStepIndex === steps.length - 1;
	const progress = Math.floor((currentStepIndex + 1) / steps.length * 100);
	const { heading: headingKey, description: descriptionKey } = contextMap$2[currentStep.id] || {};
	const navigateBack = () => {
		setCurrentStep(steps[currentStepIndex - 1]);
	};
	const navigateNext = async () => {
		if ((await form.validateAllFields("change")).length === 0) setCurrentStep(steps[currentStepIndex + 1]);
	};
	const handleCancelDismiss = () => {
		setIsConfirmPresented(false);
	};
	const handleConfirmDismiss = () => {
		setIsConfirmPresented(false);
		onClose();
	};
	const handleDismiss = () => {
		setIsConfirmPresented(true);
	};
	return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
		className: FormFlow_module_default.formFlow,
		children: /* @__PURE__ */ jsxs(form.AppForm, { children: [/* @__PURE__ */ jsx("div", {
			className: FormFlow_module_default.formFlowContent,
			children: /* @__PURE__ */ jsx("form", {
				onSubmit: (e) => {
					e.preventDefault();
					form.handleSubmit();
				},
				children: /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Header, {
					title: headingKey && t(($) => $[headingKey]),
					description: descriptionKey && t(($) => $[descriptionKey])
				}), currentStep.componentGroups.map((componentGroup) => {
					return componentGroup.components.map((component) => {
						const componentProps = resolveComponentProps(globals.value, component.props);
						if (component.componentType === "compound") return renderCompoundField({
							componentName: component.componentName,
							form,
							basePath: component.path,
							props: componentProps
						});
						if (component.componentType === "field") return /* @__PURE__ */ jsx(form.Field, {
							name: component.path,
							children: (field) => renderSimpleField(component.componentName, field)
						}, component.path);
					});
				})] }, currentStep.id)
			})
		}), /* @__PURE__ */ jsxs("div", {
			className: FormFlow_module_default.formFlowFooter,
			children: [steps.length !== 1 && /* @__PURE__ */ jsx(ProgressBar, {
				ariaLabel: commonT(($) => $["progress"]),
				progress
			}), /* @__PURE__ */ jsxs("div", {
				className: FormFlow_module_default.formFlowActions,
				children: [
					isFirstStep && /* @__PURE__ */ jsx(Button, {
						disabled: false,
						onClick: handleDismiss,
						variant: "secondary",
						children: commonT(($) => $["cancel"])
					}),
					!isFirstStep && /* @__PURE__ */ jsx(Button, {
						disabled: false,
						icon: "chevron-left",
						onClick: navigateBack,
						variant: "secondary",
						children: commonT(($) => $["back"])
					}),
					/* @__PURE__ */ jsx("div", {
						className: FormFlow_module_default.formFlowPrimaryActions,
						children: /* @__PURE__ */ jsx(form.Subscribe, {
							selector: (s) => [s.isSubmitting, !s.canSubmit],
							children: ([isSubmitting, isDisabled]) => isLastStep ? /* @__PURE__ */ jsx(Button, {
								type: "submit",
								onClick: () => form.handleSubmit(),
								loading: isSubmitting,
								disabled: isDisabled,
								children: commonT(($) => $["submit"])
							}) : /* @__PURE__ */ jsx(Button, {
								onClick: navigateNext,
								disabled: isDisabled,
								loading: isSubmitting,
								children: commonT(($) => $["continue"])
							})
						})
					})
				]
			})]
		})] })
	}), isConfirmPresented && /* @__PURE__ */ jsx(Confirm, {
		confirmText: commonT(($) => $["leave"]),
		description: commonT(($) => $["unsavedChangesDescription"]),
		onCancel: handleCancelDismiss,
		onConfirm: handleConfirmDismiss,
		title: commonT(($) => $["unsavedChanges"])
	})] });
}
//#endregion
//#region src/adaptiveWorkflow/components/SpecializedComponent/SpecializedComponent.tsx
/**
* A dynamic component resolver for the Adaptive Workflow Engine (AWE).
*
* Specialized components are self-contained units that handle their own field rendering,
* multi-step forms (if applicable), and data submission. They are looked up from the
* {@link specializedComponentMap} registry using the `componentName` provided by the AWE manifest.
*
* @param componentName - name used to resolve the component from the registry
* @param onComplete - Forwarded to the resolved component; called when its flow finishes
* @param onClose - Forwarded to the resolved component; called to dismiss the modal
* @param props - props returned from AWE
* @returns The matched specialized component, or an error end-state if the component
*          is not found in the registry or the `id` is missing
*/
var SpecializedComponent = ({ componentName, onComplete, onClose, props }) => {
	const { globals } = useWorkflowContext();
	const Component = specializedComponentMap[componentName];
	const mappedProps = useComputed(() => {
		return resolveComponentProps(globals.value, props);
	});
	if (Component) return /* @__PURE__ */ jsx(Component, {
		onComplete,
		onClose,
		...mappedProps.value
	});
	return /* @__PURE__ */ jsx(EndStateLayout, {
		title: "Something went wrong",
		description: "Something went wrong on our end, please try again later",
		variant: "error"
	});
};
//#endregion
//#region src/adaptiveWorkflow/components/Task/contextMap.ts
var contextMap$1 = {
	additionalBusinessDetails: {
		title: "additionalBusinessDetails",
		icon: "company"
	},
	identityScreening: {
		title: "enhancedIdentityScreening",
		icon: "user"
	},
	sourceOfFunds: {
		title: "fundingSources",
		icon: "coins"
	},
	taxReporting: {
		title: "taxReporting",
		icon: "document"
	},
	contracting: {
		title: "servicesAgreement",
		icon: "reporting"
	}
};
//#endregion
//#region src/adaptiveWorkflow/components/Task/Task.tsx
/**
* Component which accepts the Task-specific configuration returned from AWE to render
* a specific task. Each task can render either further sub-tasks, a dynamic form, or one specialized component
*/
var Task = (props) => {
	const { id, steps, component } = props;
	const { t } = useTranslation("adaptive");
	const { t: commonT } = useTranslation("common");
	const { title, icon } = contextMap$1[id] || {};
	const { taskStatuses, updateTaskStatus } = useWorkflowContext();
	const [showModal, setShowModal] = useState(false);
	const taskStatus = useComputed(() => taskStatuses.value[id] ?? TaskStatuses.DETAILS_REQUIRED);
	const handleTaskClick = () => {
		setShowModal(true);
	};
	const handleCloseClick = () => {
		setShowModal(false);
	};
	const handleComplete = () => {
		updateTaskStatus(id, TaskStatuses.FINISHED);
		setShowModal(false);
	};
	return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(TaskListItem, {
		titleKey: "task",
		title: title ? t(($) => $[title]) : commonT(($) => $["additionalInformation"]),
		icon,
		status: taskStatus.value,
		onNavigateToTask: () => handleTaskClick()
	}), showModal && /* @__PURE__ */ jsxs(Modal, {
		onClose: handleCloseClick,
		size: "large",
		transition: "slideIn",
		showCloseButton: true,
		ariaLabel: "modal",
		children: [steps && /* @__PURE__ */ jsx(DynamicForm, {
			onClose: handleCloseClick,
			onComplete: handleComplete,
			steps
		}), component && /* @__PURE__ */ jsx(SpecializedComponent, {
			...component,
			onComplete: handleComplete,
			onClose: handleCloseClick
		})]
	})] });
};
//#endregion
//#region src/adaptiveWorkflow/components/TaskGroup/contextMap.ts
var contextMap = {
	businessInformation: {
		heading: "businessInformation",
		description: "placeholder"
	},
	financialProducts: {
		heading: "setUpFinancialProducts",
		description: "placeholder"
	},
	contracting: {
		heading: "reviewAndSignLegalDisclosures",
		description: "placeholder"
	}
};
//#endregion
//#region src/adaptiveWorkflow/components/TaskGroup/TaskGroup.tsx
/**
* Uses task group ID and task group context map to render the copy related to a specific task group
* Also renders the nested tasks associated with a particular task group
*/
var TaskGroup = ({ id, tasks }) => {
	const { t } = useTranslation("adaptive");
	const { heading: headingKey, description: descriptionKey } = contextMap[id] || {};
	return /* @__PURE__ */ jsxs(StackLayout, {
		gap: "xSmall",
		children: [/* @__PURE__ */ jsx(Header, {
			title: headingKey ? t(($) => $[headingKey]) : t(($) => $["additionalDetails"]),
			description: descriptionKey && t(($) => $[descriptionKey])
		}), tasks.map((task) => /* @__PURE__ */ jsx(Task, { ...task }, task.id))]
	});
};
//#endregion
//#region src/adaptiveWorkflow/components/TaskGroupParser/TaskGroupParser.tsx
/**
* Parses TaskGroupConfig returned from AWE to render task groups
*/
var TaskGroupParser = ({ taskGroups }) => {
	return /* @__PURE__ */ jsx(StackLayout, { children: taskGroups.map((taskGroup) => /* @__PURE__ */ jsx(TaskGroup, { ...taskGroup }, taskGroup.id)) });
};
//#endregion
//#region src/adaptiveWorkflow/components/WorkflowHeading/WorkflowHeading.tsx
var getHeadingCopy = (globalStatus, t) => {
	switch (globalStatus) {
		case "ACTION_REQUIRED": return {
			title: t(($) => $["wereAlmostThere"]),
			description: t(($) => $["youreInTheHomeStretch"])
		};
		default: return {
			title: t(($) => $["welcomeBack"]),
			description: t(($) => $["weveReusedYourExistingMerchantProfile"])
		};
	}
};
var WorkflowHeading = ({ globalStatus }) => {
	const { t } = useTranslation("adaptive");
	const { title, description } = getHeadingCopy(globalStatus, t);
	return /* @__PURE__ */ jsx(Header, {
		title,
		description
	});
};
//#endregion
//#region src/adaptiveWorkflow/components/WorkflowEndState/WorkflowEndState.tsx
var STATUSES_WITH_WORKFLOW_END_STATE = new Set(["ACTIVATION", "READY"]);
var getEndStateConfig = (globalStatus, t) => {
	switch (globalStatus) {
		case "ACTIVATION": return {
			title: t(($) => $["weveGotItFromHere"]),
			description: t(($) => $["yourDetailsHaveBeenSubmitted"]),
			variant: "info"
		};
		case "READY": return {
			title: t(($) => $["ready"]),
			description: t(($) => $["youreAllSet"]),
			variant: "success"
		};
		default: return;
	}
};
var WorkflowEndState = ({ status, handleBack }) => {
	const { t } = useTranslation("adaptive");
	const endStateConfig = getEndStateConfig(status, t);
	const action = handleBack ? /* @__PURE__ */ jsx(Button, {
		fullWidth: true,
		onClick: handleBack,
		children: t(($) => $["returnToPlatform"])
	}) : void 0;
	return endStateConfig ? /* @__PURE__ */ jsx(EndStateLayout, {
		title: endStateConfig.title,
		description: endStateConfig.description,
		variant: endStateConfig.variant,
		action
	}) : null;
};
//#endregion
//#region src/adaptiveWorkflow/AdaptiveWorkflow.tsx
var getTaskIdsFromTasks = (tasks) => tasks.flatMap((task) => [task.id, ...task.subTasks ? getTaskIdsFromTasks(task.subTasks) : []]);
var getTaskIds = (taskGroups) => taskGroups.flatMap(({ tasks }) => getTaskIdsFromTasks(tasks));
/**
* Main home page for Adaptive Onboarding Workflow
*/
var AdaptiveWorkflow = ({ uiManifest, onBack }) => {
	const { refetch: refetchWorkflowManifest } = useAdaptiveWorkflow();
	const { entity, globals, globalStatus, taskGroups } = uiManifest;
	const { t: commonT } = useTranslation("common");
	const { setGlobals, setEntity, taskStatuses, setTaskStatuses } = useWorkflowContext();
	const allTasksCompleted = useComputed(() => {
		return Object.values(taskStatuses.value).every((status) => status === TaskStatuses.FINISHED);
	});
	useEffect(() => {
		setGlobals(globals || {});
		setEntity(entity || {});
		if (taskGroups) setTaskStatuses(Object.fromEntries(getTaskIds(taskGroups).map((id) => [id, TaskStatuses.DETAILS_REQUIRED])));
	}, [
		globals,
		entity,
		taskGroups,
		setGlobals,
		setEntity,
		setTaskStatuses
	]);
	const showWorkflowEndState = STATUSES_WITH_WORKFLOW_END_STATE.has(globalStatus);
	const handleSubmit = () => {
		refetchWorkflowManifest();
	};
	const handleBack = () => {
		onBack?.();
	};
	return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", { className: AdaptiveWorkflow_module_default.adaptiveWorkflowHeader }), showWorkflowEndState ? /* @__PURE__ */ jsx(WorkflowEndState, {
		status: globalStatus,
		handleBack
	}) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs("div", {
		className: AdaptiveWorkflow_module_default.adaptiveWorkflowMain,
		children: [
			/* @__PURE__ */ jsx(WorkflowHeading, { globalStatus }),
			/* @__PURE__ */ jsx("div", {
				className: AdaptiveWorkflow_module_default.adaptiveWorkflowDivider,
				children: /* @__PURE__ */ jsx(Divider, {})
			}),
			taskGroups && /* @__PURE__ */ jsx(TaskGroupParser, { taskGroups })
		]
	}), /* @__PURE__ */ jsx("div", {
		className: AdaptiveWorkflow_module_default.adaptiveWorkflowActions,
		children: /* @__PURE__ */ jsxs(StackLayout, {
			gap: "small",
			children: [/* @__PURE__ */ jsx(Button, {
				onClick: handleSubmit,
				fullWidth: true,
				disabled: !allTasksCompleted.value,
				children: commonT(($) => $["submit"])
			}), onBack && /* @__PURE__ */ jsx(Button, {
				variant: "tertiary",
				onClick: handleBack,
				fullWidth: true,
				children: commonT(($) => $["back"])
			})]
		})
	})] })] });
};
//#endregion
export { AdaptiveWorkflow, useAdaptiveWorkflow as n, WorkflowContext as t };
