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] = "736316d9-44b1-4e92-984e-d5935290308c", e._sentryDebugIdIdentifier = "sentry-dbid-736316d9-44b1-4e92-984e-d5935290308c");
} catch (e) {}
import { t as LegalEntityTypes } from "./legal-entity-type-VIfNYnJP.js";
import { t as CountryCodes } from "./country-code-D3oCpE4i.js";
import { t as TaskTypes } from "./taskTypes-DWaxzvnQ.js";
//#region src/utils/entityAssociationUtil.ts
/**
* Returns the entity associations from the root LE which have a {@link LegalEntityAssociation.associatorId} matching the given `legalEntityId`.
* Can be used to find members of a trust, or decision makers of a trustee company.
*
* @param rootLE the root legal entity which holds all the entity associations
* @param legalEntityId the ID of the legal entity whose associations we wish to find
*/
var getDirectEntityAssociations = (rootLE, legalEntityId) => rootLE?.entityAssociations?.filter((association) => association.associatorId === legalEntityId) ?? [];
var getOwnEntityAssociations = (legalEntity) => getDirectEntityAssociations(legalEntity, legalEntity.id);
var getOwnSoleProprietorshipIdArray = (legalEntity) => {
	return getOwnEntityAssociations(legalEntity).filter((ea) => ea.entityType === LegalEntityTypes.SOLE_PROPRIETORSHIP).map((ea) => ea.legalEntityId).filter((id) => id !== void 0);
};
var hasSolePropInLegalEntity = (rootLegalEntity) => rootLegalEntity.entityAssociations?.some((ea) => ea.entityType === LegalEntityTypes.SOLE_PROPRIETORSHIP && ea.associatorId === rootLegalEntity.id) ?? false;
var getOwnSolePropProblems = (rootLegalEntity, capabilityProblems) => {
	const solePropLegalEntityId = getOwnSoleProprietorshipIdArray(rootLegalEntity)[0];
	return capabilityProblems?.LegalEntity?.[solePropLegalEntityId];
};
var hasOwnEntityAssociationOfType = (type, entityAssociations, legalEntityId) => entityAssociations?.some((ea) => ea.type === type && ea.associatorId === legalEntityId) ?? false;
var removeEntityAssociationByType = (type, entityAssociations, legalEntityId) => entityAssociations.filter((ea) => ea.type !== type || ea.associatorId !== legalEntityId);
var isRootLegalEntity = (legalEntity, taskType) => legalEntity.type === LegalEntityTypes.INDIVIDUAL && taskType === TaskTypes.INDIVIDUAL || legalEntity.type === LegalEntityTypes.ORGANIZATION && taskType === TaskTypes.BUSINESS_DETAILS;
var filterOutUnwantedAssociationsIfRootLE = (taskType, legalEntity, accountHolder) => {
	if (!legalEntity?.entityAssociations) return;
	let entityAssociations = getOwnEntityAssociations(legalEntity);
	if (!isRootLegalEntity(legalEntity, taskType)) return entityAssociations;
	if (accountHolder !== "mySoleProprietorName" && hasOwnEntityAssociationOfType(LegalEntityTypes.SOLE_PROPRIETORSHIP, entityAssociations, legalEntity.id)) entityAssociations = removeEntityAssociationByType(LegalEntityTypes.SOLE_PROPRIETORSHIP, entityAssociations, legalEntity.id);
	if (accountHolder !== "aTrust" && hasOwnEntityAssociationOfType(LegalEntityTypes.TRUST, entityAssociations, legalEntity.id)) entityAssociations = removeEntityAssociationByType(LegalEntityTypes.TRUST, entityAssociations, legalEntity.id);
	return entityAssociations;
};
var getLegalRepresentative = (legalEntityResponse) => getDirectEntityAssociations(legalEntityResponse, legalEntityResponse.id).find((la) => la.type === "legalRepresentative");
var allowedCountriesForNominee = [CountryCodes.NewZealand];
var attachNomineeToRole = (existingEntityAssociation, country, nominee) => {
	const clonedEntity = { ...existingEntityAssociation };
	if (!allowedCountriesForNominee.includes(country) || !nominee) return existingEntityAssociation;
	if (clonedEntity.type === "uboThroughOwnership") clonedEntity.nominee = nominee?.isNomineeShareholder === "Yes" || nominee?.nomineeShareholder === "Yes";
	if (clonedEntity.type === "director") clonedEntity.nominee = nominee?.isNomineeDirector === "Yes" || nominee?.nomineeDirector === "Yes";
	return clonedEntity;
};
var getNomineeFromAssociation = (entityAssociations, basicDetails) => {
	if (!entityAssociations?.length) return basicDetails;
	const clonedBasicDetails = { ...basicDetails };
	entityAssociations.forEach((entityAssociation) => {
		if (entityAssociation.type === "uboThroughOwnership") clonedBasicDetails.nomineeShareholder = entityAssociation.nominee ? "Yes" : "No";
		if (entityAssociation.type === "director") clonedBasicDetails.nomineeDirector = entityAssociation.nominee ? "Yes" : "No";
	});
	return clonedBasicDetails;
};
var hasNomineesChanged = (basicDetails, nomineesSubmitted) => {
	return !(basicDetails?.nomineeShareholder === nomineesSubmitted?.nomineeShareholder && basicDetails?.nomineeDirector === nomineesSubmitted?.nomineeDirector);
};
//#endregion
export { getLegalRepresentative as a, getOwnSolePropProblems as c, hasOwnEntityAssociationOfType as d, hasSolePropInLegalEntity as f, getDirectEntityAssociations as i, getOwnSoleProprietorshipIdArray as l, attachNomineeToRole as n, getNomineeFromAssociation as o, filterOutUnwantedAssociationsIfRootLE as r, getOwnEntityAssociations as s, allowedCountriesForNominee as t, hasNomineesChanged as u };
