import { n as useTranslation } from "./i18n-DoP1NB7u.js";
import { v as u } from "./vendor-preact-DThS2ZQ_.js";
import { c as useManager, o as useModuleTerminalCallbacks } from "./hooks-Da_yP_Dr.js";
import { t as IncodeComponent } from "./incodeComponent-CCP7GTMj.js";
import { r as Spacer } from "./loadingIcon-B0ysgiNq.js";
import { t as Page } from "./page-DidH_RkX.js";
import "./extensibility-DesSYynI.js";
import { t as Button } from "./button-BMYTQ8fc.js";
import { t as VerificationResult } from "./verificationResult-Brj8WSyW.js";
import { t as InputComposed } from "./inputComposed-C1R2LAa3.js";
import { t as registerIncodeModuleElement } from "./incodeModule-M8DszCee.js";
import { createFieldComparisonManager } from "@incodetech/core/field-comparison";
//#region src/modules/field-comparison/fieldComparison.tsx
var FieldComparisonContent = ({ config, manager: externalManager, onFinish }) => {
	const { t } = useTranslation();
	const [state, manager] = useManager(() => externalManager ?? createFieldComparisonManager({ config }), {
		manageLifecycle: !externalManager,
		autoLoad: true
	});
	useModuleTerminalCallbacks({
		status: state.status === "finished" ? "finished" : "loading",
		onFinish
	});
	const handleSubmit = (e) => {
		e.preventDefault();
		manager.submit();
	};
	if (state.status === "finished") return null;
	if (state.status === "error") return /* @__PURE__ */ u(VerificationResult, {
		status: "failure",
		onRetry: manager.retry,
		onSkip: manager.skip
	});
	if (state.status === "success") return /* @__PURE__ */ u(VerificationResult, {
		status: "success",
		successTitle: t("customFields.completed")
	});
	if (state.status === "submitting" || state.status === "inputting") {
		const isDisabled = state.status === "submitting";
		const canSubmit = state.status === "inputting" && state.canSubmit;
		return /* @__PURE__ */ u(Page, {
			className: "IncodeFieldComparisonPage",
			title: t("fieldComparison.title"),
			hideFooterBranding: true,
			children: /* @__PURE__ */ u("div", {
				class: "IncodeFieldComparisonForm",
				children: [
					/* @__PURE__ */ u(InputComposed, {
						id: "field-comparison-first-name",
						name: "firstName",
						label: t("verification.labels.firstName"),
						disabled: isDisabled,
						value: state.fields.firstName,
						onInput: (e) => {
							manager.setField("firstName", e.target.value);
						}
					}),
					/* @__PURE__ */ u(InputComposed, {
						id: "field-comparison-last-name",
						name: "lastName",
						label: t("verification.labels.lastName"),
						disabled: isDisabled,
						value: state.fields.lastName,
						onInput: (e) => {
							manager.setField("lastName", e.target.value);
						}
					}),
					/* @__PURE__ */ u(Spacer, {}),
					/* @__PURE__ */ u(Button, {
						type: "submit",
						disabled: !canSubmit || isDisabled,
						onClick: handleSubmit,
						children: t("common.continue")
					})
				]
			})
		});
	}
	return null;
};
var FieldComparison = ({ config = {}, manager, onFinish }) => /* @__PURE__ */ u(IncodeComponent, { children: /* @__PURE__ */ u(FieldComparisonContent, {
	config,
	manager,
	onFinish
}) });
registerIncodeModuleElement(FieldComparison, "incode-field-comparison");
//#endregion
export { FieldComparison as t };
