import { n as useTranslation, o as readStoredLanguage } from "../i18n-DoP1NB7u.js";
import { _ as y, c as z, d as T, l as A, o as P, p as d, v as u } from "../vendor-preact-DThS2ZQ_.js";
import { t as setUiConfig } from "../uiConfig-D2_wawvr.js";
import { c as useManager } from "../hooks-Da_yP_Dr.js";
import { t as IncodeComponent } from "../incodeComponent-CCP7GTMj.js";
import { t as TransitionSpinner } from "../transitionSpinner-dYLkc7PO.js";
import { t as registerIncodeModuleElement } from "../incodeModule-M8DszCee.js";
import { _ as warmupWasmIfNeeded, a as resolveApiKey, c as HEADLESS_FLOW_MODULE_KEYS, d as fetchTheme, f as initializeFlowManager, h as preloadRedirectToMobile, l as LAZY_UI_MODULES, m as preloadHomeScreen, n as useModulePreloader, o as extractIncodeStatus, p as preloadFirstModule, r as usePrefetchNextModule, s as UnsupportedModule, t as useModuleLoader, u as createFlowManager, y as TerminalErrorPage } from "../useModuleLoader-9R2L73bj.js";
import { getDeviceClass } from "@incodetech/core/device";
import { getRequiredWasmPipelines } from "@incodetech/core/flow";
import { bootstrapSession, refreshQrUrlUuid } from "@incodetech/core/session";
//#region src/shared/processing/useDelayedFlag.ts
/**
* Returns `true` only once `isTrue` has stayed `true` continuously for
* `delayMs`. Resets to `false` immediately when `isTrue` flips back.
*
* Useful to suppress transient loading indicators when an operation
* completes faster than the given threshold.
*/
function useDelayedFlag(isTrue, delayMs) {
	const [delayed, setDelayed] = d(false);
	y(() => {
		if (isTrue === false) {
			setDelayed(false);
			return;
		}
		const timeoutId = window.setTimeout(() => {
			setDelayed(true);
		}, delayMs);
		return () => {
			window.clearTimeout(timeoutId);
		};
	}, [isTrue, delayMs]);
	return delayed;
}
//#endregion
//#region src/modules/flow/createFlowSession.ts
async function createFlowSession(config, signal) {
	return bootstrapSession(await resolveApiKey(config), {
		configurationId: config.configurationId,
		externalId: config.externalId,
		externalCustomerId: config.externalCustomerId,
		language: config.lang,
		customFields: config.customFields,
		uuid: config.uuid,
		urlUuid: config.urlUuid,
		interviewId: config.interviewId,
		loginHint: config.loginHint,
		onUrlUuidRefreshed: config.onUrlUuidRefreshed
	}, signal);
}
//#endregion
//#region src/modules/flow/flowConfig.ts
function hasFlowToken(config) {
	return typeof config.token === "string";
}
function isSelfLoadingFlowConfig(config) {
	const bootstrapConfig = config;
	return typeof bootstrapConfig.configurationId === "string" && (typeof bootstrapConfig.apiKey === "string" || typeof bootstrapConfig.clientId === "string");
}
//#endregion
//#region src/modules/flow/preloadFlow.ts
var preloadCache = /* @__PURE__ */ new Map();
function createPreloadHandle(token) {
	const state = preloadCache.get(token);
	if (!state) throw new Error("Preload state not found");
	return {
		get isReady() {
			return state.status === "ready";
		},
		get error() {
			return state.status === "error" ? state.error ?? null : null;
		},
		async waitUntilReady() {
			if (state.status === "ready") return;
			if (state.status === "error") throw new Error(state.error ?? "Preload failed");
			return state.readyPromise;
		},
		cancel() {
			if (state.status === "loading") {
				if (state.unsubscribe) state.unsubscribe();
				state.flowManager.stop();
				state.readyReject(/* @__PURE__ */ new Error("Preload cancelled"));
				preloadCache.delete(token);
			}
		}
	};
}
function preloadIncodeFlow(config) {
	const { token } = config;
	if (config.urlUuid) throw new Error("preloadIncodeFlow does not support urlUuid; pass it to <IncodeFlow> directly so the SDK can rotate it on mount.");
	if (preloadCache.has(token)) return createPreloadHandle(token);
	let readyResolve;
	let readyReject;
	const readyPromise = new Promise((resolve, reject) => {
		readyResolve = resolve;
		readyReject = reject;
	});
	const flowManager = createFlowManager(config);
	if (flowManager.getState().presentation.shouldPrefetchHome) preloadHomeScreen();
	const state = {
		status: "loading",
		flowManager,
		config,
		readyPromise,
		readyResolve,
		readyReject
	};
	preloadCache.set(token, state);
	const preload = async () => {
		try {
			await initializeFlowManager({
				token: config.token,
				lang: config.lang,
				flowManager
			});
			const themePromise = config.disableDashboardTheme ? Promise.resolve({}) : fetchTheme().then((result) => {
				state.theme = result.theme;
				state.uiConfig = result.uiConfig;
			});
			state.unsubscribe = flowManager.subscribe((managerState) => {
				if (managerState.status === "ready") {
					const readyState = managerState;
					warmupWasmIfNeeded(readyState, config.wasmConfig);
					preloadFirstModule(readyState);
					state.unsubscribe?.();
					state.unsubscribe = void 0;
					state.status = "ready";
					state.readyResolve();
				} else if (managerState.status === "error") {
					state.unsubscribe?.();
					state.unsubscribe = void 0;
					state.status = "error";
					state.error = managerState.error;
					state.readyReject(new Error(managerState.error));
				}
			});
			await themePromise;
		} catch (error) {
			state.status = "error";
			state.error = error instanceof Error ? error.message : "Failed to preload";
			state.readyReject(error instanceof Error ? error : /* @__PURE__ */ new Error("Failed to preload"));
			preloadCache.delete(token);
		}
	};
	preload();
	return createPreloadHandle(token);
}
function getPreloadedData(token) {
	return preloadCache.get(token) ?? null;
}
function consumePreloadedData(token) {
	const state = getPreloadedData(token);
	if (state) preloadCache.delete(token);
	return state;
}
//#endregion
//#region src/modules/flow/useFlowInitialization.ts
function maybePreloadHomeScreen(flowManager) {
	if (flowManager.getState().presentation.shouldPrefetchHome) preloadHomeScreen();
}
function maybePreloadRedirectToMobile() {
	if (getDeviceClass() === "desktop") preloadRedirectToMobile();
}
function useFlowInitialization(options) {
	const { lang, disableDashboardTheme, enableHome, onError, useCPF } = options;
	const token = hasFlowToken(options) ? options.token : void 0;
	const flowManagerRef = A(null);
	const [state, setState] = d(() => {
		const preloaded = token ? getPreloadedData(token) : null;
		if (token) {
			if (preloaded?.status === "ready") {
				const consumed = consumePreloadedData(token);
				if (consumed) {
					flowManagerRef.current = consumed.flowManager;
					maybePreloadHomeScreen(consumed.flowManager);
					maybePreloadRedirectToMobile();
					if (consumed.uiConfig) setUiConfig(consumed.uiConfig);
					return {
						status: "ready",
						flowManager: consumed.flowManager
					};
				}
			}
		}
		const flowManager = createFlowManager({
			authHint: options.authHint,
			lang: options.lang,
			enableHome: options.enableHome,
			useCPF: options.useCPF
		});
		flowManagerRef.current = flowManager;
		maybePreloadHomeScreen(flowManager);
		maybePreloadRedirectToMobile();
		if (preloaded?.status === "error") return {
			status: "error",
			error: preloaded.error ?? "Preload failed",
			flowManager
		};
		return {
			status: "initializing",
			flowManager
		};
	});
	const initStartedRef = A(false);
	y(() => {
		if (state.status !== "initializing") return;
		const preloaded = token ? getPreloadedData(token) : null;
		if (token && preloaded?.status === "loading") {
			preloaded.readyPromise.then(() => {
				const consumed = consumePreloadedData(token);
				if (consumed) {
					flowManagerRef.current = consumed.flowManager;
					maybePreloadHomeScreen(consumed.flowManager);
					maybePreloadRedirectToMobile();
					if (consumed.uiConfig) setUiConfig(consumed.uiConfig);
					setState({
						status: "ready",
						flowManager: consumed.flowManager
					});
				}
			}).catch((error) => {
				const errorMessage = error instanceof Error ? error.message : "Preload failed";
				const errorCode = extractIncodeStatus(error);
				setState({
					status: "error",
					error: errorMessage,
					errorCode,
					flowManager: state.flowManager
				});
				onError?.(errorMessage, errorCode);
			});
			return;
		}
		if (initStartedRef.current) return;
		initStartedRef.current = true;
		const abortController = new AbortController();
		const { signal } = abortController;
		const initialize = async () => {
			try {
				let resolvedToken;
				if (hasFlowToken(options)) {
					resolvedToken = options.token;
					if (options.urlUuid) await refreshQrUrlUuid({
						urlUuid: options.urlUuid,
						onboardingId: null,
						onRefreshed: options.onUrlUuidRefreshed
					}, signal);
				} else if (isSelfLoadingFlowConfig(options)) {
					const session = await createFlowSession(options, signal);
					resolvedToken = session.token;
					state.flowManager.setEndScreenTexts(session.endScreenTitle ?? null, session.endScreenText ?? null);
				} else throw new Error("Flow requires token, or configurationId with apiKey or clientId");
				await initializeFlowManager({
					token: resolvedToken,
					lang,
					flowManager: state.flowManager
				});
				const themePromise = disableDashboardTheme ? Promise.resolve() : fetchTheme().then((result) => {
					if (result.uiConfig) setUiConfig(result.uiConfig);
				});
				const flowReadyPromise = state.flowManager.waitForReady();
				await Promise.all([flowReadyPromise, themePromise]);
				setState({
					status: "ready",
					flowManager: state.flowManager
				});
			} catch (error) {
				if (signal.aborted) return;
				const errorMessage = error instanceof Error ? error.message : "Failed to initialize SDK";
				const errorCode = extractIncodeStatus(error);
				setState({
					status: "error",
					error: errorMessage,
					errorCode,
					flowManager: state.flowManager
				});
				onError?.(errorMessage, errorCode);
			}
		};
		initialize();
		return () => abortController.abort();
	}, [
		token,
		lang,
		disableDashboardTheme,
		enableHome,
		useCPF,
		onError,
		options,
		state
	]);
	return state;
}
//#endregion
//#region src/modules/flow/flow.tsx
var LazyHomeScreen = z(() => import("../homeScreen-W6-PF75j.js").then((module) => ({ default: module.HomeScreen })));
var IncodeFlowContent = ({ config, onFinish, onError }) => {
	const { i18n } = useTranslation();
	const initState = useFlowInitialization(T(() => ({
		...config,
		onError
	}), [config, onError]));
	const [flowState, flowManager] = useManager(() => initState.flowManager, { autoLoad: false });
	const lazyModuleKey = flowState.presentation.lazyModuleKey;
	const currentModuleKey = flowState.status === "ready" ? flowState.currentStep : void 0;
	const moduleLoaderState = useModuleLoader({
		moduleKey: lazyModuleKey,
		modules: LAZY_UI_MODULES,
		onModuleLoading: config.onModuleLoading,
		onModuleLoaded: config.onModuleLoaded,
		onError
	});
	useModulePreloader({
		moduleKey: flowState.status === "ready" && flowState.homeScreen.visible ? currentModuleKey : void 0,
		modules: LAZY_UI_MODULES
	});
	const currentModuleLoaded = moduleLoaderState.status === "loaded";
	const showHomeLoadingScreen = config.enableHome === true && flowState.status === "ready" && flowState.flow.disableLaunchScreen !== true && flowState.currentStepIndex === 0 && flowState.homeScreen.visible === false && moduleLoaderState.status === "loading";
	const isAwaitingReadyDelayed = useDelayedFlag(flowState.presentation.isAwaitingReady === true, 150);
	const isModuleLoadingDelayed = useDelayedFlag(flowState.status === "ready" && (moduleLoaderState.status === "idle" || moduleLoaderState.status === "loading" || moduleLoaderState.status === "error"), 150);
	usePrefetchNextModule(flowState?.status === "ready" ? flowState.steps : [], flowState?.status === "ready" ? flowState.currentStepIndex : -1, LAZY_UI_MODULES, currentModuleLoaded);
	y(() => {
		if (!config.onFlowEvent) return;
		return flowManager.subscribeFlowEvent(config.onFlowEvent);
	}, [flowManager, config.onFlowEvent]);
	y(() => {
		if (flowState.presentation.shouldPrefetchHome) preloadHomeScreen();
	}, [flowState.presentation.shouldPrefetchHome]);
	y(() => {
		if (readStoredLanguage()) return;
		if (config.lang && i18n.language !== config.lang) i18n.changeLanguage(config.lang);
	}, [config.lang, i18n]);
	y(() => {
		if (flowState?.status !== "ready") return;
		if (flowState.currentStep === "REDIRECT_TO_MOBILE") return;
		const readyState = flowState;
		const requiredPipelines = getRequiredWasmPipelines(readyState.flow);
		if (requiredPipelines.length > 0) {
			config.onWasmWarmup?.(requiredPipelines);
			warmupWasmIfNeeded(readyState, config.wasmConfig);
		}
	}, [flowState, config]);
	const terminalFiredRef = A(false);
	y(() => {
		if (terminalFiredRef.current) return;
		if (flowState?.status === "finished") {
			terminalFiredRef.current = true;
			const finishStatus = flowState.finishStatus;
			queueMicrotask(() => onFinish(finishStatus));
			return;
		}
		if (flowState?.status === "error" && onError) {
			terminalFiredRef.current = true;
			const { error, errorCode } = flowState;
			queueMicrotask(() => onError(error, errorCode));
		}
	}, [
		flowState?.status,
		onFinish,
		onError,
		flowState
	]);
	y(() => {
		if (flowState?.status === "ready" && flowState.currentStep === "ID" && flowState.steps.includes("TUTORIAL_ID")) flowManager.completeModule();
	}, [flowState, flowManager]);
	const hideSpinnerText = !(config.spinnerConfig?.title || config.spinnerConfig?.subtitle);
	if (initState.status === "error") return /* @__PURE__ */ u("div", {
		class: "IncodeFlow",
		children: /* @__PURE__ */ u(TerminalErrorPage, { message: initState.error })
	});
	if (flowState.homeScreen.visible || showHomeLoadingScreen) return /* @__PURE__ */ u("div", {
		class: "IncodeFlow",
		children: /* @__PURE__ */ u(P, {
			fallback: null,
			children: /* @__PURE__ */ u(LazyHomeScreen, {
				isContinueLoading: flowState.homeScreen.isContinueLoading || showHomeLoadingScreen,
				onContinue: () => flowManager.continueFromHome()
			})
		})
	});
	if (initState.status === "initializing") return /* @__PURE__ */ u("div", {
		class: "IncodeFlow",
		children: /* @__PURE__ */ u(TransitionSpinner, {
			spinnerConfig: config.spinnerConfig,
			hideText: hideSpinnerText
		})
	});
	if (flowState.presentation.isAwaitingReady) {
		if (!isAwaitingReadyDelayed) return /* @__PURE__ */ u("div", { class: "IncodeFlow" });
		return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(TransitionSpinner, {
				spinnerConfig: config.spinnerConfig,
				hideText: hideSpinnerText
			})
		});
	}
	if (flowState.status === "error") return /* @__PURE__ */ u("div", {
		class: "IncodeFlow",
		children: /* @__PURE__ */ u(TerminalErrorPage, { message: flowState.error })
	});
	if (flowState.status === "finished") return null;
	if (flowState?.status === "ready") {
		const { currentStep, config: flowConfig, flow } = flowState;
		const { flowId } = flow;
		if (!currentStep || !flowConfig) return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(TransitionSpinner, {
				spinnerConfig: config.spinnerConfig,
				hideText: hideSpinnerText
			})
		});
		if (HEADLESS_FLOW_MODULE_KEYS.has(currentStep)) return /* @__PURE__ */ u("div", { class: "IncodeFlow" });
		if (moduleLoaderState.status === "unsupported") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(UnsupportedModule, {
				moduleKey: currentStep,
				onNext: () => flowManager.completeModule()
			})
		});
		if (moduleLoaderState.status === "idle" || moduleLoaderState.status === "loading" || moduleLoaderState.status === "error") {
			if (!isModuleLoadingDelayed) return /* @__PURE__ */ u("div", { class: "IncodeFlow" });
			return /* @__PURE__ */ u("div", {
				class: "IncodeFlow",
				children: /* @__PURE__ */ u(TransitionSpinner, {
					spinnerConfig: config.spinnerConfig,
					hideText: hideSpinnerText
				})
			});
		}
		const { Component } = moduleLoaderState;
		if (currentStep === "REDIRECT_TO_MOBILE") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.finishFlow(),
				onContinue: () => flowManager.completeModule(),
				onError
			}, `redirect-to-mobile-${flowState.currentStepIndex}`)
		});
		if (currentStep === "SELFIE") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Selfie verification error");
				}
			}, `selfie-${flowState.currentStepIndex}`)
		});
		if (currentStep === "AUTHENTICATION") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: {
					...flowConfig,
					authHint: config.authHint
				},
				onFinish: () => flowManager.completeModule(),
				onError: (error, _errorCode, moduleErrorCode) => flowManager.errorModule(error ?? "Authentication error", moduleErrorCode)
			}, `authentication-${flowState.currentStepIndex}`)
		});
		if (currentStep === "PHONE") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Phone verification error");
				}
			}, `phone-${flowState.currentStepIndex}`)
		});
		if (currentStep === "EMAIL") {
			const emailConfig = flowConfig;
			if (!emailConfig || typeof emailConfig.otpVerification !== "boolean" || typeof emailConfig.otpExpirationInMinutes !== "number") return /* @__PURE__ */ u("div", {
				class: "IncodeFlow",
				children: /* @__PURE__ */ u("div", { children: "Error: Invalid email configuration" })
			});
			return /* @__PURE__ */ u("div", {
				class: "IncodeFlow",
				children: /* @__PURE__ */ u(Component, {
					config: emailConfig,
					onFinish: () => flowManager.completeModule(),
					onError: (error) => {
						onError?.(error ?? "Email verification error");
					}
				}, `email-${flowState.currentStepIndex}`)
			});
		}
		if (currentStep === "ID" || currentStep === "SECOND_ID") {
			const idConfig = flowConfig;
			return /* @__PURE__ */ u("div", {
				class: "IncodeFlow",
				children: /* @__PURE__ */ u(Component, {
					config: currentStep === "SECOND_ID" ? {
						...idConfig,
						isSecondId: true
					} : idConfig,
					onFinish: () => flowManager.completeModule(),
					onError: (error) => {
						onError?.(error ?? "ID capture error");
					}
				}, `id-${flowState.currentStepIndex}`)
			});
		}
		if (currentStep === "ID_OCR") {
			const idOcrConfig = flowConfig;
			const isSecondId = flowState.steps.includes("SECOND_ID");
			return /* @__PURE__ */ u("div", {
				class: "IncodeFlow",
				children: /* @__PURE__ */ u(Component, {
					config: {
						...idOcrConfig,
						secondId: idOcrConfig.secondId ?? isSecondId,
						flowId
					},
					onFinish: () => flowManager.completeModule(),
					onError: (error) => {
						onError?.(error ?? "ID OCR error");
					}
				}, `id-ocr-${flowState.currentStepIndex}`)
			});
		}
		if (currentStep === "CPF_OCR") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "CPF OCR error");
				}
			}, `cpf-ocr-${flowState.currentStepIndex}`)
		});
		if (currentStep === "FACE_MATCH") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Face match error");
				}
			}, `face-match-${flowState.currentStepIndex}`)
		});
		if (currentStep === "CURP_VALIDATION") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "CURP validation error");
				}
			}, `curp-validation-${flowState.currentStepIndex}`)
		});
		if (currentStep === "GOVT_VALIDATION_PROVISIONING") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Government validation error");
				}
			}, `govt-validation-${flowState.currentStepIndex}`)
		});
		if (currentStep === "INE_VALIDATION") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "INE validation error");
				}
			}, `ine-validation-${flowState.currentStepIndex}`)
		});
		if (currentStep === "GEOLOCATION") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Geolocation error");
				}
			}, `geolocation-${flowState.currentStepIndex}`)
		});
		if (currentStep === "EXTERNAL_VERIFICATION") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: { flowId: flowState.flow.flowId },
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "External verification error");
				}
			}, `ekyc-${flowState.currentStepIndex}`)
		});
		if (currentStep === "DOCUMENT_CAPTURE") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Document capture error");
				}
			}, `document-capture-${flowState.currentStepIndex}`)
		});
		if (currentStep === "ADDRESS") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: {
					...flowConfig,
					processingType: "addressStatement"
				},
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Address capture error");
				}
			}, `address-${flowState.currentStepIndex}`)
		});
		if (currentStep === "SIGNATURE") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Signature capture error");
				}
			}, `signature-${flowState.currentStepIndex}`)
		});
		if (currentStep === "EKYB") {
			const ekybFlowConfig = flowConfig;
			return /* @__PURE__ */ u("div", {
				class: "IncodeFlow",
				children: /* @__PURE__ */ u(Component, {
					config: {
						flowId,
						checkBusinessName: ekybFlowConfig.checkBusinessName,
						checkAddress: ekybFlowConfig.checkAddress,
						checkTaxId: ekybFlowConfig.checkTaxId,
						checkUniqueBeneficialOwner: ekybFlowConfig.checkUniqueBeneficialOwner
					},
					onFinish: () => flowManager.completeModule(),
					onError: (error) => {
						onError?.(error ?? "eKYB verification error");
					}
				}, `ekyb-${flowState.currentStepIndex}`)
			});
		}
		if (currentStep === "COMBINED_CONSENT") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Combined consent error");
				}
			}, `combined-consent-${flowState.currentStepIndex}`)
		});
		if (currentStep === "MANDATORY_CONSENT" || currentStep === "ML_CONSENT") {
			const isMlConsent = currentStep === "ML_CONSENT";
			return /* @__PURE__ */ u("div", {
				class: "IncodeFlow",
				children: /* @__PURE__ */ u(Component, {
					config: {
						...flowConfig,
						type: isMlConsent ? "ML" : "MANDATORY"
					},
					onFinish: () => flowManager.completeModule(),
					onError: (error) => {
						onError?.(error ?? (isMlConsent ? "ML consent error" : "Mandatory consent error"));
					}
				}, `${isMlConsent ? "ml" : "mandatory"}-consent-${flowState.currentStepIndex}`)
			});
		}
		if (currentStep === "AE_SIGNATURE" || currentStep === "QE_SIGNATURE") {
			const sigConfig = flowConfig;
			const label = currentStep === "QE_SIGNATURE" ? "qe" : "ae";
			return /* @__PURE__ */ u("div", {
				class: "IncodeFlow",
				children: /* @__PURE__ */ u(Component, {
					config: {
						uploadDocument: sigConfig.uploadDocument,
						downloadDocument: sigConfig.downloadDocument
					},
					onFinish: () => flowManager.completeModule(),
					onError: (error) => {
						onError?.(error ?? `${label.toUpperCase()} Signature error`);
					}
				}, `${label}-signature-${flowState.currentStepIndex}`)
			});
		}
		if (currentStep === "ANTIFRAUD") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Antifraud check error");
				}
			}, `antifraud-${flowState.currentStepIndex}`)
		});
		if (currentStep === "CUSTOM_FIELDS") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Custom fields error");
				}
			}, `custom-fields-${flowState.currentStepIndex}`)
		});
		if (currentStep === "WATCHLIST") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Watchlist check error");
				}
			}, `watchlist-${flowState.currentStepIndex}`)
		});
		if (currentStep === "WATCHLIST_BUSINESS") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Watchlist for business check error");
				}
			}, `watchlist-for-business-${flowState.currentStepIndex}`)
		});
		if (currentStep === "INCODE_WATCHLIST") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Custom watchlist check error");
				}
			}, `incode-watchlist-${flowState.currentStepIndex}`)
		});
		if (currentStep === "CROSS_DOCUMENT_DATA_MATCH") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Cross document data match error");
				}
			}, `cross-document-data-match-${flowState.currentStepIndex}`)
		});
		if (currentStep === "CERTIFICATE_ISSUANCE") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: flowConfig,
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Certificate issuance error");
				}
			}, `certificate-issuance-${flowState.currentStepIndex}`)
		});
		if (currentStep === "FIELD_COMPARISON") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Field comparison error");
				}
			}, `field-comparison-${flowState.currentStepIndex}`)
		});
		if (currentStep === "DYNAMIC_FORMS") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				config: { screens: flowConfig.screens.map((s) => ({
					title: s.title,
					hideTitle: s.hideTitle,
					questions: s.questions.map((q) => ({
						questionId: q.questionId,
						question: q.question,
						inputType: q.inputType,
						isOptional: q.isOptional,
						overrides: q.overrides ?? void 0,
						isPredefined: q.isPredefined,
						options: q.options
					}))
				})) },
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Dynamic forms error");
				}
			}, `dynamic-forms-${flowState.currentStepIndex}`)
		});
		if (currentStep === "FISCAL_QR") return /* @__PURE__ */ u("div", {
			class: "IncodeFlow",
			children: /* @__PURE__ */ u(Component, {
				onFinish: () => flowManager.completeModule(),
				onError: (error) => {
					onError?.(error ?? "Fiscal QR error");
				}
			}, `fiscal-qr-${flowState.currentStepIndex}`)
		});
	}
	return null;
};
var IncodeFlow = ({ config, onFinish = () => {}, onError }) => {
	return /* @__PURE__ */ u(IncodeComponent, { children: config ? /* @__PURE__ */ u(IncodeFlowContent, {
		config,
		onFinish,
		onError
	}) : null });
};
registerIncodeModuleElement(IncodeFlow, "incode-flow");
//#endregion
export { IncodeFlow, preloadIncodeFlow };
