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] = "f8edd0a8-65c6-4e15-b911-a24433f046a3", e._sentryDebugIdIdentifier = "sentry-dbid-f8edd0a8-65c6-4e15-b911-a24433f046a3");
} catch (e) {}
import { a as Icon, n as addResourceBundles, r as useTranslation, t as Trans } from "./translation-Br5wIPO-.js";
import { r as Loader, t as Button } from "./Button-BDEdGXnd.js";
import { r as useLegalEntity, t as ROOT_LE } from "./useLegalEntity-Dm6g0wmt.js";
import { t as LegalEntityTypes } from "./legal-entity-type-VIfNYnJP.js";
import { t as useToggleContext } from "./useToggleContext-CLfowItk.js";
import { t as _rolldown_dynamic_import_helper_default } from "./_rolldown_dynamic_import_helper-CCXvMgfE.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 { t as CountryCodes } from "./country-code-D3oCpE4i.js";
import { t as Alert } from "./Alert-CjZYipjN.js";
import { t as TaskTypes } from "./taskTypes-DWaxzvnQ.js";
import { s as getOwnEntityAssociations } from "./entityAssociationUtil-C0gX4Ewv.js";
import { r as useGetTaskStatus } from "./globalStore-D0yv1fc_.js";
import { n as getDecisionMakerDescriptionMap } from "./decisionMaker-BKR5Dau-.js";
import { r as TrustMemberTypes, t as TRUST_DEFAULT_DESCRIPTIONS_MAP } from "./trustMemberGuidance-paR1FXfI.js";
import { s as DEFAULT_TRUST_MEMBER_REQUIREMENTS } from "./trustUtil-CVipffas.js";
import { t as useToastContext } from "./useToastContext-CK7UoZ5Z.js";
import { t as useAssociatedLegalEntity } from "./useAssociatedLegalEntity-CYu0lsaE.js";
import { t as useTrustMembers } from "./useTrustMembers-BP6ygpU4.js";
import { t as UnincorporatedPartnershipMemberTypes } from "./unincorporated-partnership-CtwHVLzp.js";
import { t as useUpdateLegalEntity } from "./useUpdateLegalEntity-CUs6TYPF.js";
import { n as getRoleTagVariant, t as getRoleName } from "./roleMetadata-Dt8-oMGP.js";
import { t as ContextGuidance } from "./ContextGuidance-CxOv00_a.js";
import { t as Spacer } from "./Spacer-D1yp_1Io.js";
import { t as Tag } from "./Tag-BTQ4nyKS.js";
import { t as EntityAssociation } from "./EntityAssociation-inLOmBfG.js";
import { Fragment, jsx, jsxs } from "preact/jsx-runtime";
//#region src/components/UnincorporatedPartnership/tasks/UnincorporatedPartnershipMembers/types.ts
var UNINCORPORATED_PARTNERSHIP__DEFAULT_DESCRIPTIONS_MAP = {
	[UnincorporatedPartnershipMemberTypes.SECONDARY_PARTNER]: "provideAtLeastOneSecondaryPartner",
	[UnincorporatedPartnershipMemberTypes.OWNER]: "provideAllOwners",
	[UnincorporatedPartnershipMemberTypes.CONTROLLING_PERSON]: "ifNoOwnersSpecifyControllingPersons"
};
//#endregion
//#region src/utils/entityStatusUtil.ts
/**
* Determines the status of an entity based on the current and minimum values.
*
* This function compares the `current` number of entities provided with the `min` entities required.
* If the `current` value is greater than 0 and is greater than or equal to `min`,
* it returns `'satisfied'`. Otherwise, it returns `'empty'`.
*
* @param {number} current - The current value to be evaluated.
* @param {number} min - The minimum threshold that `current` must meet or exceed.
* @returns {EntityStatus} - Returns `'satisfied'` if the current value meets the condition, otherwise `'empty'`.
*/
var iconStatus = (current, min) => {
	return current > 0 && current >= min ? "satisfied" : "empty";
};
var getEntityStatusRuleDescription = (country, currentTask, entityLabel) => {
	const defaultMessage = getDecisionMakerDescriptionMap(country)[entityLabel];
	switch (currentTask) {
		case TaskTypes.TRUST_MEMBER_OVERVIEW: return TRUST_DEFAULT_DESCRIPTIONS_MAP[entityLabel];
		case TaskTypes.UNINCORPORATED_PARTNERSHIP_MEMBER_OVERVIEW: return UNINCORPORATED_PARTNERSHIP__DEFAULT_DESCRIPTIONS_MAP[entityLabel] || defaultMessage;
		default: return defaultMessage;
	}
};
//#endregion
//#region src/components/Shared/EntityGuidanceStatus/EntityStatusIcon.tsx
var EntityStatusIcon = ({ status }) => {
	switch (status) {
		case "empty": return /* @__PURE__ */ jsx(Icon, {
			name: "checkmark-circle",
			className: "adyen-kyc-entity-status__icon adyen-kyc-entity-status__icon--empty",
			testId: "empty-icon"
		});
		case "satisfied": return /* @__PURE__ */ jsx(Icon, {
			name: "checkmark",
			className: "adyen-kyc-entity-status__icon adyen-kyc-entity-status__icon--satisfied",
			testId: "satisfied-icon"
		});
		default: return /* @__PURE__ */ jsx(Icon, {
			name: "circle",
			className: "adyen-kyc-entity-status__icon adyen-kyc-entity-status__icon--empty",
			testId: "empty-icon"
		});
	}
};
//#endregion
//#region src/components/Shared/EntityGuidanceStatus/EntityGuidanceStatus.tsx
var EntityGuidanceStatus = ({ country, currentTask, entityLabel, status }) => {
	const { t } = useTranslation("common");
	return /* @__PURE__ */ jsxs("div", {
		className: "adyen-kyc-entity-status__container",
		children: [
			/* @__PURE__ */ jsx(EntityStatusIcon, { status }),
			/* @__PURE__ */ jsx(Tag, {
				className: "adyen-kyc-entity-status__tag",
				variant: getRoleTagVariant(entityLabel),
				children: t(($) => $[getRoleName(entityLabel)])
			}, entityLabel),
			/* @__PURE__ */ jsx("span", {
				className: "adyen-kyc-entity-status--text",
				"data-testid": `${entityLabel}-rule--description`,
				children: /* @__PURE__ */ jsx(Trans, {
					t,
					i18nKey: ($) => $[getEntityStatusRuleDescription(country, currentTask, entityLabel)]
				})
			})
		]
	});
};
//#endregion
//#region src/components/Trust/utils/deleteAssociatedTrustMember.ts
var deleteAssociatedTrustMember = async ({ associatedTrustMember, trust, asyncMutation }) => {
	const ownEntityAssociations = getOwnEntityAssociations(trust);
	await asyncMutation({
		id: trust.id,
		entityAssociations: ownEntityAssociations.filter((entityAssociation) => entityAssociation.legalEntityId !== associatedTrustMember.legalEntityId)
	});
};
//#endregion
//#region src/components/Trust/utils/deleteUndefinedBeneficiary.ts
/**
* Undefined Beneficiaries are not entity associations,
* therefore their deletion and updation are different from that of a usual trust member
*/
var deleteUndefinedBeneficiary = async ({ undefinedBeneficiary, trust, asyncMutation }) => {
	const existingUndefinedBeneficiaries = trust.trust?.undefinedBeneficiaryInfo ?? [];
	await asyncMutation({
		id: trust.id,
		trust: { undefinedBeneficiaryInfo: existingUndefinedBeneficiaries.filter((ub) => ub.reference !== undefinedBeneficiary.reference) }
	});
};
//#endregion
//#region src/components/Trust/tasks/TrustMembers/CompanyTrustMemberTaskItem.tsx
var CompanyTrustMemberTaskItem = ({ companyTrustMember, taskStatus, onEditOwner, onAddOwner, onEdit, onDelete }) => {
	const { t } = useTranslation(["trust", "common"]);
	const actions = [
		{
			icon: "edit",
			onSelect: onEdit,
			label: t(($) => $["editTrustMember"], { trustMember: companyTrustMember.name })
		},
		companyTrustMember.ownerId ? {
			icon: "edit",
			onSelect: onEditOwner,
			label: t(($) => $["editOwnerOfTrustMember"], { trustMember: companyTrustMember.name })
		} : {
			icon: "plus",
			onSelect: onAddOwner,
			label: t(($) => $["addOwnerToTrustMember"], { trustMember: companyTrustMember.name })
		},
		{
			icon: "bin",
			onSelect: onDelete,
			label: t(($) => $["removeTrustMember"], { trustMember: companyTrustMember.name })
		}
	];
	const infoContent = companyTrustMember.ownerId ? void 0 : /* @__PURE__ */ jsx(Alert, {
		title: /* @__PURE__ */ jsxs(Fragment, { children: [
			t(($) => $["helpUsVerifyCompany"], { ns: "common" }),
			" ",
			/* @__PURE__ */ jsx(Button, {
				onClick: onAddOwner,
				variant: "link",
				children: t(($) => $["providePersonalDetailsOfOwner"])
			})
		] }),
		className: "add-owner-alert"
	});
	return /* @__PURE__ */ jsx(EntityAssociation, {
		types: companyTrustMember.roles,
		name: companyTrustMember.name,
		status: taskStatus,
		actions,
		infoContent,
		onNavigateToEntity: onEdit
	}, companyTrustMember.legalEntityId);
};
//#endregion
//#region src/components/Trust/tasks/TrustMembers/ExemptSettlorTaskItem.tsx
var ExemptSettlorTaskItem = ({ exemptSettlor, taskStatus, onEdit, onDelete }) => {
	const { t } = useTranslation("trust");
	const settlorName = exemptSettlor.legalEntityType === LegalEntityTypes.INDIVIDUAL ? `${exemptSettlor.exemptSettlorName?.firstName} ${exemptSettlor.exemptSettlorName?.lastName}` : exemptSettlor.name ?? "";
	const actions = [{
		icon: "edit",
		onSelect: onEdit,
		label: t(($) => $["editTrustMember"], { trustMember: settlorName })
	}, {
		icon: "bin",
		onSelect: onDelete,
		label: t(($) => $["removeTrustMember"], { trustMember: settlorName })
	}];
	return /* @__PURE__ */ jsx(EntityAssociation, {
		types: exemptSettlor.roles,
		name: settlorName,
		status: taskStatus,
		actions,
		onNavigateToEntity: onEdit
	}, exemptSettlor.legalEntityId);
};
//#endregion
//#region src/components/Trust/tasks/TrustMembers/RegularTrustMemberTaskItem.tsx
var RegularTrustMemberTaskItem = ({ trustMember, taskStatus, onEdit, onDelete }) => {
	const { t } = useTranslation("trust");
	const actions = [{
		icon: "edit",
		onSelect: onEdit,
		label: t(($) => $["editTrustMember"], { trustMember: trustMember.name })
	}, {
		icon: "bin",
		onSelect: onDelete,
		label: t(($) => $["removeTrustMember"], { trustMember: trustMember.name })
	}];
	return /* @__PURE__ */ jsx(EntityAssociation, {
		types: trustMember.roles,
		name: trustMember.name,
		status: taskStatus,
		actions,
		onNavigateToEntity: onEdit
	}, trustMember.legalEntityId);
};
//#endregion
//#region src/components/Trust/tasks/TrustMembers/RootTrusteeTaskItem.tsx
var RootTrusteeTaskItem = ({ rootTrustee, taskStatus, onEdit }) => {
	const { t } = useTranslation("trust");
	const actions = [{
		icon: "edit",
		onSelect: onEdit,
		label: t(($) => $["editTrustMember"], { trustMember: rootTrustee.name })
	}];
	const { isFeatureEnabled } = useToggleContext();
	const isAllowMoreRolesForMainRootTrustee = isFeatureEnabled("AllowMoreRolesForMainRootTrustee");
	return /* @__PURE__ */ jsx(EntityAssociation, {
		types: isFeatureEnabled("AllowMoreRolesForMainRootTrustee") ? rootTrustee.roles : [TrustMemberTypes.TRUSTEE],
		name: rootTrustee.name,
		status: taskStatus,
		actions: isAllowMoreRolesForMainRootTrustee ? actions : void 0
	});
};
//#endregion
//#region src/components/Trust/tasks/TrustMembers/UndefinedBeneficiaryTaskItem.tsx
var UndefinedBeneficiaryTaskItem = ({ undefinedBeneficiary, onEdit, onDelete }) => {
	const { t } = useTranslation("trust");
	const actions = [{
		icon: "edit",
		onSelect: onEdit,
		label: t(($) => $["editTrustMember"], { trustMember: t(($) => $["undefinedBeneficiary"]) })
	}, {
		icon: "bin",
		onSelect: onDelete,
		label: t(($) => $["removeTrustMember"], { trustMember: t(($) => $["undefinedBeneficiary"]) })
	}];
	return /* @__PURE__ */ jsx(EntityAssociation, {
		name: undefinedBeneficiary.description,
		types: [TrustMemberTypes.UNDEFINED_BENEFICIARY],
		status: TaskStatuses.FINISHED,
		actions,
		onNavigateToEntity: onEdit
	}, undefinedBeneficiary.reference);
};
//#endregion
//#region src/components/Trust/tasks/TrustMembers/TrustMembersOverview.tsx
var TrustMembersOverview = ({ navigateBackToTaskList, navigateToEditTrustMember, navigateToEditTrustMemberOwner }) => {
	const { t, i18n } = useTranslation("trust");
	const { data: rootLe, isLoading } = useLegalEntity(ROOT_LE);
	const { data: trustLe, refetch: refetchTrust } = useAssociatedLegalEntity(rootLe, LegalEntityTypes.TRUST);
	const trustMembers = useTrustMembers();
	const { mutateAsync: updateLegalEntity } = useUpdateLegalEntity();
	const { showToast } = useToastContext();
	addResourceBundles(i18n, [{
		ns: "trust",
		importFn: (lang) => _rolldown_dynamic_import_helper_default(/* @__PURE__ */ Object.assign({
			"../../language/bg-BG.json": () => import("./bg-BG-YZ34LkMd.js"),
			"../../language/cs-CZ.json": () => import("./cs-CZ-Bl8qBkx4.js"),
			"../../language/da-DK.json": () => import("./da-DK-BOU9aCaN.js"),
			"../../language/de-DE.json": () => import("./de-DE-B8D6bV3u.js"),
			"../../language/el-GR.json": () => import("./el-GR-mGnv3b-O.js"),
			"../../language/en-US.json": () => import("./en-US-aJtjsYKh.js"),
			"../../language/es-ES.json": () => import("./es-ES-BAAL2h3R.js"),
			"../../language/et-EE.json": () => import("./et-EE-C4U93xrJ.js"),
			"../../language/fi-FI.json": () => import("./fi-FI-IwaR92iX.js"),
			"../../language/fr-FR.json": () => import("./fr-FR-DwYX21r1.js"),
			"../../language/hr-HR.json": () => import("./hr-HR-CFAySNqh.js"),
			"../../language/hu-HU.json": () => import("./hu-HU-DXHf3uuK.js"),
			"../../language/it-IT.json": () => import("./it-IT-BK6Yn4vc.js"),
			"../../language/ja-JP.json": () => import("./ja-JP-B5fRnSzi.js"),
			"../../language/lt-LT.json": () => import("./lt-LT-Dkvuak-E.js"),
			"../../language/lv-LV.json": () => import("./lv-LV-Cz0igciN.js"),
			"../../language/nl-NL.json": () => import("./nl-NL-BTuDiajY.js"),
			"../../language/no-NO.json": () => import("./no-NO-D6C6Imfk.js"),
			"../../language/pl-PL.json": () => import("./pl-PL-DNdGYT-E.js"),
			"../../language/pt-BR.json": () => import("./pt-BR-BgiNMjMc.js"),
			"../../language/pt-PT.json": () => import("./pt-PT-CWzCKCL8.js"),
			"../../language/ro-RO.json": () => import("./ro-RO-DLtPW1MX.js"),
			"../../language/sk-SK.json": () => import("./sk-SK-DNKyL6Hl.js"),
			"../../language/sl-SI.json": () => import("./sl-SI-DNgxTuIJ.js"),
			"../../language/sv-SE.json": () => import("./sv-SE-BM8WESGs.js")
		}), `../../language/${lang}.json`, 4)
	}]);
	if (isLoading || !rootLe || !trustLe) return /* @__PURE__ */ jsx(Loader, { size: "large" });
	const deleteTrustMember = async (trustMember) => {
		try {
			switch (trustMember.trustMemberType) {
				case "regular":
				case "exemptSettlor":
				case "company":
					await deleteAssociatedTrustMember({
						associatedTrustMember: trustMember,
						trust: trustLe,
						asyncMutation: updateLegalEntity
					});
					break;
				case "undefinedBeneficiary":
					await deleteUndefinedBeneficiary({
						undefinedBeneficiary: trustMember,
						trust: trustLe,
						asyncMutation: updateLegalEntity
					});
					break;
				case "rootTrustee": throw new Error("Cannot delete root trustee");
			}
			await refetchTrust();
			showToast({
				variant: "success",
				label: t(($) => $["successFullyRemovedTrustMember"])
			});
		} catch {
			showToast({
				variant: "error",
				label: t(($) => $["failedToRemoveTrustMember"])
			});
		}
	};
	return /* @__PURE__ */ jsx(TrustMembersOverviewInner, {
		trustMembers,
		deleteTrustMember,
		navigateBackToTaskList,
		navigateToEditTrustMember,
		navigateToEditTrustMemberOwner
	});
};
var TrustMembersOverviewInner = ({ trustMembers, deleteTrustMember, navigateBackToTaskList, navigateToEditTrustMember, navigateToEditTrustMemberOwner }) => {
	const { t } = useTranslation(["trust", "common"]);
	const trustMemberRequirements = DEFAULT_TRUST_MEMBER_REQUIREMENTS;
	const trustMembersWithOneOfGivenRoles = (roleTypes) => trustMembers.filter(({ roles }) => roleTypes.some((label) => roles.includes(label)));
	const { isFeatureEnabled } = useToggleContext();
	const allowMoreRolesForMainRootTrustee = isFeatureEnabled("AllowMoreRolesForMainRootTrustee");
	const getTaskStatus = useGetTaskStatus();
	return /* @__PURE__ */ jsxs("div", {
		className: "adyen-kyc-trust-members u-width-full u-margin-16",
		children: [
			/* @__PURE__ */ jsx(Header, {
				title: t(($) => $["trustMembers"]),
				description: t(($) => $["trustMembersDescription"])
			}),
			/* @__PURE__ */ jsx("div", { children: trustMemberRequirements.map(({ roleTypes, min, label }) => /* @__PURE__ */ jsx(EntityGuidanceStatus, {
				country: CountryCodes.Australia,
				currentTask: TaskTypes.TRUST_MEMBER_OVERVIEW,
				entityLabel: label,
				status: iconStatus(trustMembersWithOneOfGivenRoles(roleTypes).length, min)
			}, label)) }),
			/* @__PURE__ */ jsx(ContextGuidance, {
				title: t(($) => $["whatIsTheDifferenceBetweenTheseRoles"]),
				content: /* @__PURE__ */ jsx("ul", {
					className: "adyen-kyc-guidance-list",
					children: trustMemberRequirements.map(({ label }) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsx(Trans, {
						t,
						ns: "trust",
						i18nKey: ($) => $[`${label}GuideDescription`]
					}) }, label))
				}),
				titleId: "whatIsTheDifferenceBetweenTheseRoles",
				contentId: "differenceBetweenTrustMemberRoles"
			}),
			/* @__PURE__ */ jsx(StackLayout, {
				gap: "small",
				children: trustMembers.map((trustMember) => {
					switch (trustMember.trustMemberType) {
						case "rootTrustee": return /* @__PURE__ */ jsx(RootTrusteeTaskItem, {
							rootTrustee: trustMember,
							taskStatus: getTaskStatus(trustMember.legalEntityType == "organization" ? TaskTypes.TRUST_MEMBER_COMPANY : TaskTypes.TRUST_MEMBER_INDIVIDUAL, String(trustMember.legalEntityId)),
							onEdit: allowMoreRolesForMainRootTrustee ? () => navigateToEditTrustMember(trustMember) : () => {}
						}, trustMember.legalEntityId);
						case "regular": return /* @__PURE__ */ jsx(RegularTrustMemberTaskItem, {
							trustMember,
							taskStatus: getTaskStatus(TaskTypes.TRUST_MEMBER_INDIVIDUAL, String(trustMember.legalEntityId)),
							onEdit: () => navigateToEditTrustMember(trustMember),
							onDelete: () => deleteTrustMember(trustMember)
						}, trustMember.legalEntityId);
						case "company": return /* @__PURE__ */ jsx(CompanyTrustMemberTaskItem, {
							companyTrustMember: trustMember,
							taskStatus: getTaskStatus(TaskTypes.TRUST_MEMBER_COMPANY, String(trustMember.legalEntityId)),
							onEdit: () => navigateToEditTrustMember(trustMember),
							onDelete: () => deleteTrustMember(trustMember),
							onEditOwner: () => navigateToEditTrustMemberOwner(trustMember.ownerId, trustMember.legalEntityId),
							onAddOwner: () => navigateToEditTrustMemberOwner("", trustMember.legalEntityId)
						}, trustMember.legalEntityId);
						case "exemptSettlor": return /* @__PURE__ */ jsx(ExemptSettlorTaskItem, {
							exemptSettlor: trustMember,
							taskStatus: getTaskStatus(TaskTypes.TRUST_MEMBER_INDIVIDUAL, String(trustMember.legalEntityId)),
							onEdit: () => navigateToEditTrustMember(trustMember),
							onDelete: () => deleteTrustMember(trustMember)
						}, trustMember.legalEntityId);
						case "undefinedBeneficiary": return /* @__PURE__ */ jsx(UndefinedBeneficiaryTaskItem, {
							undefinedBeneficiary: trustMember,
							onEdit: () => navigateToEditTrustMember(trustMember),
							onDelete: () => deleteTrustMember(trustMember)
						}, trustMember.reference);
					}
				})
			}),
			/* @__PURE__ */ jsx("div", {
				className: "u-margin-top-24",
				children: /* @__PURE__ */ jsx(Button, {
					variant: "secondary",
					icon: "plus",
					onClick: (e) => {
						e.stopPropagation();
						navigateToEditTrustMember("new");
					},
					children: t(($) => $["addTrustMember"])
				})
			}),
			/* @__PURE__ */ jsxs("div", {
				class: "u-display-flex u-margin-top-48",
				children: [/* @__PURE__ */ jsx(Spacer, {}), /* @__PURE__ */ jsx(Button, {
					variant: "secondary",
					onClick: navigateBackToTaskList,
					children: t(($) => $["saveAndGoToOverview"], { ns: "common" })
				})]
			})
		]
	});
};
//#endregion
export { TrustMembersOverview };
