;
{
  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] = "61b0aba4-d9cd-4846-a879-f3f0904276ed", e._sentryDebugIdIdentifier = "sentry-dbid-61b0aba4-d9cd-4846-a879-f3f0904276ed");
  } catch (e) {
  }
}
;
import { ae as getOwnEntityAssociations, u as useTranslation, V as Button, o as LegalEntityTypes, v as useExperimentsContext, bn as TrustMemberTypes, q as TaskStatuses, c as useLegalEntity, a as addResourceBundles, L as Loader, R as ROOT_LE, y as useGetTaskStatus, bz as DEFAULT_TRUST_MEMBER_REQUIREMENTS, j as TaskTypes, a0 as CountryCodes, aB as Trans, _ as __variableDynamicImportRuntimeHelper } from "./StoreProvider-CqQrndhS.js";
import { jsx, jsxs, Fragment } from "preact/jsx-runtime";
import { u as useUpdateLegalEntity } from "./useUpdateLegalEntity-CcNBhTXa.js";
import { H as Header } from "./Header-Dt-hNg1U.js";
import { u as useToastContext } from "./useToastContext-CPvuqSMm.js";
import { u as useAssociatedLegalEntity } from "./useAssociatedLegalEntity-C4OxYq45.js";
import { u as useTrustMembers } from "./useTrustMembers-Bu1X3sQq.js";
import { S as StackLayout } from "./unincorporated-partnership-MeN1dp53.js";
import { C as ContextGuidance } from "./ContextGuidance-BESxqmbz.js";
import { A as ActionBar } from "./ActionBar-DPfNdSxA.js";
import { D as DropinLayout } from "./DropinLayout-CBP_cHLC.js";
import { E as EntityGuidanceStatus, i as iconStatus } from "./EntityGuidanceStatus-gPHo-N2L.js";
import { a as Alert } from "./Alert-CpDg47bv.js";
import { E as EntityAssociation } from "./EntityAssociation-BABkwZ5a.js";
const deleteAssociatedTrustMember = async ({
  associatedTrustMember,
  trust,
  asyncMutation
}) => {
  const ownEntityAssociations = getOwnEntityAssociations(trust);
  const updatedTrustAssociations = {
    entityAssociations: ownEntityAssociations.filter(
      (entityAssociation) => entityAssociation.legalEntityId !== associatedTrustMember.legalEntityId
    )
  };
  await asyncMutation({ ...updatedTrustAssociations, id: trust.id });
};
const deleteUndefinedBeneficiary = async ({
  undefinedBeneficiary,
  trust,
  asyncMutation
}) => {
  const existingUndefinedBeneficiaries = trust.trust?.undefinedBeneficiaryInfo ?? [];
  const updatedTrust = {
    trust: {
      undefinedBeneficiaryInfo: existingUndefinedBeneficiaries.filter(
        (ub) => ub.reference !== undefinedBeneficiary.reference
      )
    }
  };
  await asyncMutation({ ...updatedTrust, id: trust.id });
};
const 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
  );
};
const 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
  );
};
const 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
  );
};
const RootTrusteeTaskItem = ({
  rootTrustee,
  taskStatus,
  onEdit
}) => {
  const { t } = useTranslation("trust");
  const actions = [
    {
      icon: "edit",
      onSelect: onEdit,
      label: t(($) => $["editTrustMember"], { trustMember: rootTrustee.name })
    }
  ];
  const { isExperimentEnabled } = useExperimentsContext();
  const isAllowMoreRolesForMainRootTrustee = isExperimentEnabled(
    "AllowMoreRolesForMainRootTrustee"
  );
  return /* @__PURE__ */ jsx(
    EntityAssociation,
    {
      types: isExperimentEnabled("AllowMoreRolesForMainRootTrustee") ? rootTrustee.roles : [TrustMemberTypes.TRUSTEE],
      name: rootTrustee.name,
      status: taskStatus,
      actions: isAllowMoreRolesForMainRootTrustee ? actions : void 0
    }
  );
};
const 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
  );
};
const 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) => __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "../../language/bg-BG.json": () => import("./bg-BG-DMNRRZZE.js"), "../../language/cs-CZ.json": () => import("./cs-CZ-DXSMRqPu.js"), "../../language/da-DK.json": () => import("./da-DK-Cd5IQPv3.js"), "../../language/de-DE.json": () => import("./de-DE-C9NH2zMh.js"), "../../language/el-GR.json": () => import("./el-GR-DTHQslLc.js"), "../../language/en-US.json": () => import("./en-US-DYP6rAvA.js"), "../../language/es-ES.json": () => import("./es-ES-DK-7qtDf.js"), "../../language/et-EE.json": () => import("./et-EE-DNC4hcxm.js"), "../../language/fi-FI.json": () => import("./fi-FI-BJLU1JHw.js"), "../../language/fr-FR.json": () => import("./fr-FR-B2je0smB.js"), "../../language/hr-HR.json": () => import("./hr-HR-C0NLgF1r.js"), "../../language/hu-HU.json": () => import("./hu-HU-DU-5ujQK.js"), "../../language/it-IT.json": () => import("./it-IT-Dhwa9Ecj.js"), "../../language/ja-JP.json": () => import("./ja-JP-Bc4U0S8-.js"), "../../language/lt-LT.json": () => import("./lt-LT-C8n1GZoU.js"), "../../language/lv-LV.json": () => import("./lv-LV-BZN4-Xat.js"), "../../language/nl-NL.json": () => import("./nl-NL-B0fvINJj.js"), "../../language/no-NO.json": () => import("./no-NO-Jw7Gae-a.js"), "../../language/pl-PL.json": () => import("./pl-PL-Bmaq3IC3.js"), "../../language/pt-BR.json": () => import("./pt-BR-BaTE6BB_.js"), "../../language/pt-PT.json": () => import("./pt-PT-c0ap84_F.js"), "../../language/ro-RO.json": () => import("./ro-RO-BPOHV6Wp.js"), "../../language/sk-SK.json": () => import("./sk-SK-3_SoEn6P.js"), "../../language/sl-SI.json": () => import("./sl-SI-DbfswGh0.js"), "../../language/sv-SE.json": () => import("./sv-SE-D_Efxy3s.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
    }
  );
};
const 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 { isExperimentEnabled } = useExperimentsContext();
  const allowMoreRolesForMainRootTrustee = isExperimentEnabled("AllowMoreRolesForMainRootTrustee");
  const getTaskStatus = useGetTaskStatus();
  return /* @__PURE__ */ jsx(
    DropinLayout,
    {
      content: /* @__PURE__ */ jsxs("div", { className: "adyen-kyc-trust-members adyen-kyc-u-width-full", children: [
        /* @__PURE__ */ jsx(
          Header,
          {
            title: t(($) => $["trustMembers"]),
            description: t(($) => $["trustMembersDescription"])
          }
        ),
        /* @__PURE__ */ jsx("div", { className: "adyen-kyc-trust-members__container", 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(
          Button,
          {
            variant: "secondary",
            icon: "plus",
            onClick: (e) => {
              e.stopPropagation();
              navigateToEditTrustMember("new");
            },
            children: t(($) => $["addTrustMember"])
          }
        ),
        /* @__PURE__ */ jsx(
          ActionBar,
          {
            onHome: navigateBackToTaskList,
            homeButtonLabel: t(($) => $["saveAndGoToOverview"], { ns: "common" })
          }
        )
      ] })
    }
  );
};
export {
  TrustMembersOverview,
  TrustMembersOverviewInner
};
