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] = "eb3b0712-42c1-4c08-b334-be7f3946c569", e._sentryDebugIdIdentifier = "sentry-dbid-eb3b0712-42c1-4c08-b334-be7f3946c569");
} catch (e) {}
import { a as Icon, o as createLogger, r as useTranslation } from "./translation-Br5wIPO-.js";
import { t as Button } from "./Button-BDEdGXnd.js";
import { t as useSettingsContext } from "./useSettingsContext-DzwVt0W0.js";
import { c as entriesOf, u as valuesOf } from "./AnalyticsContext-C0HNdPss.js";
import { t as useToggleContext } from "./useToggleContext-CLfowItk.js";
import { t as listToRecord } from "./listToRecord-CVX8Zg0w.js";
import { t as TaskVerificationStatus } from "./TaskVerificationStatus-jBBIJN_A.js";
import { t as Accordion } from "./Accordion-DJ1F7dI4.js";
import { a as splitTaskIdentifier, i as useGlobalStore } from "./globalStore-D0yv1fc_.js";
import { t as SettingNames } from "./types-BklAlvuU.js";
import { t as Modal } from "./Modal-DOC6JgPI.js";
import { n as FeatureNames, t as ExperimentNames } from "./types-LOiahAxg.js";
import { t as formDebugInfo } from "./debugStore-BVjLDPIU.js";
import { t as Checkbox } from "./Checkbox-BJJIXNHL.js";
import { t as InputText } from "./InputText-CadVntiC.js";
import { t as Tag } from "./Tag-BTQ4nyKS.js";
import { useMemo, useState } from "preact/hooks";
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
import MonogonCode from "monogon/preact";
var Tabs_module_default = { tabs: "adyen-kyc-tabs" };
//#endregion
//#region src/components/ui/molecules/Tabs/Tabs.tsx
var Tabs = ({ tabs, activeTab, onChange }) => /* @__PURE__ */ jsx("div", {
	className: Tabs_module_default.tabs,
	children: tabs.map(({ name, label, disabled }) => {
		return /* @__PURE__ */ jsx(Button, {
			onClick: () => {
				onChange(name);
			},
			variant: activeTab === name ? "secondary" : "tertiary",
			disabled,
			children: label
		}, name);
	})
});
var DebugFormData_module_default = {
	searchInput: "adyen-kyc-searchInput",
	toolbar: "adyen-kyc-toolbar",
	fieldHeader: "adyen-kyc-fieldHeader",
	status: "adyen-kyc-status",
	statusRequired: "adyen-kyc-statusRequired",
	statusOptional: "adyen-kyc-statusOptional",
	statusHidden: "adyen-kyc-statusHidden",
	statusInfo: "adyen-kyc-statusInfo",
	reasonsList: "adyen-kyc-reasonsList",
	reasonItem: "adyen-kyc-reasonItem"
};
//#endregion
//#region src/components/Shared/devex/DebugListener/DebugFormData.tsx
var statusClassNames = {
	REQUIRED: DebugFormData_module_default.statusRequired,
	OPTIONAL: DebugFormData_module_default.statusOptional,
	INFO: DebugFormData_module_default.statusInfo,
	HIDDEN: DebugFormData_module_default.statusHidden
};
var DebugFormData = () => {
	const debugInfo = formDebugInfo.value;
	const [searchTerm, setSearchTerm] = useState("");
	const [showHidden, setShowHidden] = useState(false);
	const filteredFieldNames = [];
	for (const fieldName in debugInfo) if (fieldName.toLowerCase().includes(searchTerm.toLowerCase()) && (showHidden || debugInfo[fieldName].status !== "HIDDEN")) filteredFieldNames.push(fieldName);
	filteredFieldNames.sort((a, b) => {
		if (a === "__FORMS__") return -1;
		if (b === "__FORMS__") return 1;
		return a.localeCompare(b);
	});
	if (Object.keys(debugInfo).length === 0) return /* @__PURE__ */ jsx("p", { children: "No form debug data available. Navigate to a form to see its debug info." });
	return /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsxs("div", {
		className: DebugFormData_module_default.toolbar,
		children: [/* @__PURE__ */ jsx("input", {
			type: "text",
			placeholder: "Search field...",
			value: searchTerm,
			onInput: (e) => setSearchTerm(e.currentTarget.value),
			className: DebugFormData_module_default.searchInput
		}), /* @__PURE__ */ jsx(Checkbox, {
			id: "show-hidden-fields",
			name: "show-hidden-fields",
			label: "Show hidden fields",
			checked: showHidden,
			onChange: () => setShowHidden(!showHidden)
		})]
	}), filteredFieldNames.map((fieldName) => {
		const info = debugInfo[fieldName];
		return /* @__PURE__ */ jsxs(Accordion, {
			onToggle: () => {},
			children: [/* @__PURE__ */ jsx("template", {
				slot: "title",
				children: /* @__PURE__ */ jsxs("div", {
					className: DebugFormData_module_default.fieldHeader,
					children: [
						/* @__PURE__ */ jsx("span", {
							className: DebugFormData_module_default.status,
							children: fieldName
						}),
						" ",
						/* @__PURE__ */ jsxs("span", {
							className: statusClassNames[info.status],
							children: [
								"(",
								info.status,
								")"
							]
						})
					]
				})
			}), /* @__PURE__ */ jsx("template", {
				slot: "content",
				children: /* @__PURE__ */ jsx("ul", {
					className: DebugFormData_module_default.reasonsList,
					children: info.reasons.map((reason) => /* @__PURE__ */ jsx("li", {
						className: DebugFormData_module_default.reasonItem,
						children: reason
					}, reason))
				})
			})]
		}, fieldName);
	})] });
};
//#endregion
//#region src/components/Shared/devex/DebugTable/DebugTable.tsx
var filterData = (data, searchTerm) => data.filter(({ key }) => key.toLowerCase().includes(searchTerm.toLowerCase()));
var sortData = (data) => [...data].sort(({ key: keyA }, { key: keyB }) => keyA.localeCompare(keyB));
var DebugTable = ({ data, heading, searchTerm, tagPosition = "after", sort = false }) => {
	const filteredData = useMemo(() => {
		const filtered = searchTerm ? filterData(data, searchTerm) : data;
		return sort ? sortData(filtered) : filtered;
	}, [data, searchTerm]);
	return /* @__PURE__ */ jsxs("div", { children: [heading ? /* @__PURE__ */ jsx("h3", { children: heading }) : void 0, filteredData.length === 0 ? /* @__PURE__ */ jsx("p", { children: searchTerm ? /* @__PURE__ */ jsxs(Fragment, { children: ["No results found for ", /* @__PURE__ */ jsx("strong", { children: searchTerm })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
		"No ",
		heading?.toLowerCase(),
		" defined"
	] }) }) : /* @__PURE__ */ jsx("table", { children: /* @__PURE__ */ jsx("tbody", { children: filteredData.map(({ key, value, label, variant }) => /* @__PURE__ */ jsxs("tr", { children: [
		tagPosition === "before" ? /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx(Tag, {
			variant: variant ?? "grey",
			children: value
		}) }) : void 0,
		/* @__PURE__ */ jsxs("td", { children: [/* @__PURE__ */ jsx("span", {
			className: "table-key",
			children: key
		}), label && /* @__PURE__ */ jsxs("span", { children: [" ", label] })] }),
		tagPosition === "after" ? /* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx(Tag, {
			variant: variant ?? "grey",
			children: value
		}) }) : void 0
	] }, `${key}-${value}-${label}`)) }) })] });
};
//#endregion
//#region src/components/Shared/devex/DebugListener/DebugLegalEntityData.tsx
var DebugLegalEntityData = ({ legalEntityData }) => {
	if (!legalEntityData) return /* @__PURE__ */ jsx(Fragment, {});
	const { rootLegalEntity, rootLegalEntityType } = legalEntityData;
	const uboDetails = [];
	if (rootLegalEntity.entityAssociations) for (const { name, type, jobTitle } of rootLegalEntity.entityAssociations) {
		if (!name) continue;
		uboDetails.push({
			key: name,
			value: `${type}`,
			label: jobTitle,
			variant: "blue"
		});
	}
	return /* @__PURE__ */ jsxs(Fragment, { children: [
		/* @__PURE__ */ jsxs("span", { children: ["Root legal entity type: ", /* @__PURE__ */ jsx(Tag, { children: rootLegalEntityType })] }),
		uboDetails.length ? /* @__PURE__ */ jsx(DebugTable, {
			data: uboDetails,
			heading: "Decision Makers"
		}) : void 0,
		rootLegalEntity ? /* @__PURE__ */ jsx(MonogonCode, {
			lang: "json",
			content: JSON.stringify(rootLegalEntity, null, 2)
		}) : void 0
	] });
};
//#endregion
//#region src/components/Shared/devex/DebugListener/DebugMetadata.tsx
var DebugMetadata = ({ metadata: { sdkVersion, locale, rootLegalEntityId } }) => {
	return /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(DebugTable, { data: [
		{
			key: "SDK version",
			value: sdkVersion,
			variant: "green"
		},
		{
			key: "Locale",
			value: locale,
			variant: "blue"
		},
		{
			key: "Root legal entity ID",
			value: rootLegalEntityId,
			variant: "teal"
		}
	] }) });
};
var DebugModal_module_default = {
	"debug-modal": "adyen-kyc-debug-modal",
	debugModal: "adyen-kyc-debug-modal",
	"debug-header": "adyen-kyc-debug-header",
	debugHeader: "adyen-kyc-debug-header",
	"header-tabs": "adyen-kyc-header-tabs",
	headerTabs: "adyen-kyc-header-tabs",
	footer: "adyen-kyc-footer",
	"footer-copy-status": "adyen-kyc-footer-copy-status",
	footerCopyStatus: "adyen-kyc-footer-copy-status",
	"table-key": "adyen-kyc-table-key",
	tableKey: "adyen-kyc-table-key",
	content: "adyen-kyc-content",
	meta: "adyen-kyc-meta"
};
var DebugTaskStatuses_module_default = {
	header: "adyen-kyc-header",
	"task-name": "adyen-kyc-task-name",
	taskName: "adyen-kyc-task-name",
	table: "adyen-kyc-table"
};
//#endregion
//#region src/components/Shared/devex/DebugListener/DebugTaskStatuses.tsx
var DebugTaskStatuses = ({ taskStatuses }) => {
	const { t } = useTranslation("common");
	return /* @__PURE__ */ jsxs("table", {
		className: DebugTaskStatuses_module_default.table,
		children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", {
			className: DebugTaskStatuses_module_default.header,
			children: [
				/* @__PURE__ */ jsx("th", { children: t(($) => $["task"]) }),
				/* @__PURE__ */ jsx("th", { children: t(($) => $["status"]) }),
				/* @__PURE__ */ jsx("th", { children: t(($) => $["reason"]) })
			]
		}) }), /* @__PURE__ */ jsx("tbody", { children: entriesOf(taskStatuses).sort(([t1], [t2]) => t1.localeCompare(t2)).map(([task, status]) => {
			const { taskType, id } = splitTaskIdentifier(task);
			return /* @__PURE__ */ jsxs("tr", { children: [/* @__PURE__ */ jsxs("td", {
				className: DebugTaskStatuses_module_default.taskName,
				children: [taskType, id ? `: ${id}` : ""]
			}), status ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("td", { children: /* @__PURE__ */ jsx(TaskVerificationStatus, { status: status.status }) }), /* @__PURE__ */ jsxs("td", { children: [t(($) => $[status.reason]), /* @__PURE__ */ jsx(ExplainDetails, { status })] })] }) : /* @__PURE__ */ jsx(Fragment, {})] }, task);
		}) })]
	});
};
var ExplainDetails = ({ status }) => {
	const { reason, details } = status;
	switch (reason) {
		case "invalidInputError": {
			const verificationError = details.verificationError;
			const subErrors = verificationError.subErrors;
			return /* @__PURE__ */ jsxs("div", { children: [
				verificationError.code,
				": ",
				verificationError.message,
				subErrors ? /* @__PURE__ */ jsx("ul", { children: (verificationError.subErrors ?? []).map((subError) => /* @__PURE__ */ jsxs("li", { children: [
					subError.code,
					": ",
					subError.message
				] }, subError.code)) }) : /* @__PURE__ */ jsx(Fragment, {})
			] });
		}
		case "dataMissingError": {
			const verificationError = details.verificationError;
			const subErrors = verificationError.subErrors;
			return /* @__PURE__ */ jsxs("div", { children: [
				verificationError.code,
				": ",
				verificationError.message,
				subErrors ? /* @__PURE__ */ jsx("ul", { children: (verificationError.subErrors ?? []).map((subError) => /* @__PURE__ */ jsxs("li", { children: [
					subError.code,
					": ",
					subError.message
				] }, subError.code)) }) : /* @__PURE__ */ jsx(Fragment, {})
			] });
		}
		case "pendingCapabilities": {
			const pendingCapabilities = details.pendingCapabilities;
			return /* @__PURE__ */ jsx("ul", { children: pendingCapabilities.map((capabilityName) => /* @__PURE__ */ jsx("li", { children: capabilityName }, capabilityName)) });
		}
	}
};
//#endregion
//#region src/components/Shared/devex/DebugListener/DebugTogglesAndSettings.tsx
var getSettingVariant = (value) => {
	switch (value) {
		case void 0: return "orange";
		case true: return "green";
		case false: return "red";
		default: return "blue";
	}
};
var DebugTogglesAndSettings = ({ features, settings, experiments }) => {
	const [searchTerm, setSearchTerm] = useState("");
	const featureRows = entriesOf(features).map(([featureName, enabled]) => ({
		key: `${featureName}`,
		value: enabled ? "Enabled" : "Disabled",
		variant: enabled ? "green" : "red"
	}));
	const settingRows = entriesOf(settings).map(([settingName, value]) => ({
		key: settingName,
		value: `${value}`,
		variant: getSettingVariant(value)
	}));
	const experimentRows = entriesOf(experiments).map(([experimentName, enabled]) => ({
		key: `${experimentName}`,
		value: enabled ? "Enabled" : "Disabled",
		variant: enabled ? "green" : "red"
	}));
	return /* @__PURE__ */ jsxs(Fragment, { children: [
		/* @__PURE__ */ jsx(InputText, {
			name: "search",
			value: searchTerm,
			onInput: (e) => setSearchTerm(e.currentTarget.value),
			placeholder: "Search for Features/Settings 🔎",
			trimOnBlur: true,
			spellCheck: false,
			"aria-label": "Search features or settings",
			"aria-invalid": false
		}),
		/* @__PURE__ */ jsx(DebugTable, {
			tagPosition: "before",
			data: featureRows,
			heading: "Features",
			searchTerm,
			sort: true
		}),
		/* @__PURE__ */ jsx(DebugTable, {
			tagPosition: "before",
			data: experimentRows,
			heading: "Experiments",
			searchTerm,
			sort: true
		}),
		/* @__PURE__ */ jsx(DebugTable, {
			data: settingRows,
			heading: "Settings",
			searchTerm,
			sort: true
		})
	] });
};
//#endregion
//#region src/components/Shared/devex/DebugListener/DebugModal.tsx
var logger = createLogger();
var DebugModal = ({ onExit }) => {
	const { isFeatureEnabled, isExperimentEnabled } = useToggleContext();
	const { getSetting } = useSettingsContext();
	const [debugInfoCopied, setDebugInfoCopied] = useState(false);
	const { i18n } = useTranslation();
	const [tab, setTab] = useState("metadata");
	const rootLegalEntity = useGlobalStore().rootLegalEntity.value;
	const formDebugAvailable = Object.keys(formDebugInfo.value).length > 0;
	const metadata = {
		sdkVersion: "4.12.2",
		locale: i18n.language,
		rootLegalEntityId: rootLegalEntity.id
	};
	const features = listToRecord(valuesOf(FeatureNames), isFeatureEnabled);
	const experiments = listToRecord(valuesOf(ExperimentNames), isExperimentEnabled);
	const settings = listToRecord(valuesOf(SettingNames), getSetting);
	const taskStatuses = useGlobalStore().taskStatuses.value;
	const legalEntityData = {
		rootLegalEntity,
		rootLegalEntityType: rootLegalEntity.type
	};
	const copyToClipboard = async () => {
		const toCopy = {
			metadata,
			features,
			experiments,
			settings,
			taskStatuses,
			legalEntityData
		};
		await window.navigator.clipboard.writeText(JSON.stringify(toCopy, null, 2));
		setDebugInfoCopied(true);
		setTimeout(() => {
			setDebugInfoCopied(false);
		}, 5e3);
	};
	const TABS = [
		{
			name: "metadata",
			label: "Metadata"
		},
		{
			name: "toggleSettings",
			label: "Toggles & Settings"
		},
		{
			name: "taskStatuses",
			label: "Task Statuses"
		},
		{
			name: "legalEntityData",
			label: "Legal Entity Data"
		}
	];
	if (formDebugAvailable) TABS.push({
		name: "formConfig",
		label: "Form Config"
	});
	return /* @__PURE__ */ jsx(Modal, {
		size: "fullscreen",
		onClose: onExit,
		ariaLabel: "Debug",
		children: /* @__PURE__ */ jsxs("div", {
			className: DebugModal_module_default.debugModal,
			children: [
				/* @__PURE__ */ jsxs("div", {
					className: DebugModal_module_default.debugHeader,
					children: [
						/* @__PURE__ */ jsx("h1", { children: "Debug" }),
						" ",
						/* @__PURE__ */ jsx(Tabs, {
							activeTab: tab,
							onChange: (tab) => setTab(tab),
							tabs: TABS
						})
					]
				}),
				/* @__PURE__ */ jsxs("div", {
					className: DebugModal_module_default.content,
					children: [
						tab === "metadata" ? /* @__PURE__ */ jsx(DebugMetadata, { metadata }) : void 0,
						tab === "taskStatuses" ? /* @__PURE__ */ jsx(DebugTaskStatuses, { taskStatuses }) : void 0,
						tab === "toggleSettings" ? /* @__PURE__ */ jsx(DebugTogglesAndSettings, {
							features,
							settings,
							experiments
						}) : void 0,
						tab === "legalEntityData" ? /* @__PURE__ */ jsx(DebugLegalEntityData, { legalEntityData }) : void 0,
						tab === "formConfig" ? /* @__PURE__ */ jsx(DebugFormData, {}) : void 0
					]
				}),
				/* @__PURE__ */ jsx("div", {
					className: DebugModal_module_default.footer,
					children: /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx(Button, {
						icon: "document",
						onClick: () => {
							copyToClipboard().catch((error) => {
								logger.error("Error copying to clipboard:", error);
							});
						},
						children: "Copy debug info"
					}), debugInfoCopied ? /* @__PURE__ */ jsxs("span", {
						className: DebugModal_module_default.footerCopyStatus,
						children: [/* @__PURE__ */ jsx(Icon, { name: "check" }), " Copied!"]
					}) : void 0] })
				})
			]
		})
	});
};
//#endregion
export { DebugModal };
