;
{
  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] = "b6753af7-4bbb-43b7-9efd-a97782b7a341", e._sentryDebugIdIdentifier = "sentry-dbid-b6753af7-4bbb-43b7-9efd-a97782b7a341");
  } catch (e) {
  }
}
;
import { u as useTranslation, c as useLegalEntity, C as useGlobalStore, a as addResourceBundles, y as useGetTaskStatus, L as Loader, j as TaskTypes, o as LegalEntityTypes, V as Button, R as ROOT_LE, _ as __variableDynamicImportRuntimeHelper } from "./StoreProvider-CqQrndhS.js";
import { jsx, jsxs, Fragment } from "preact/jsx-runtime";
import { useEffect } from "preact/hooks";
import { u as useUpdateLegalEntity } from "./useUpdateLegalEntity-CcNBhTXa.js";
import { H as Header } from "./Header-Dt-hNg1U.js";
import { u as useAssociatedLegalEntity } from "./useAssociatedLegalEntity-C4OxYq45.js";
import { u as useUnincorporatedPartnershipMembers, d as deleteUnincorporatedPartnershipMember } from "./useUnincorporatedPartnershipMembers-B2WglS12.js";
import { S as StackLayout } from "./unincorporated-partnership-MeN1dp53.js";
import { a as Alert } from "./Alert-CpDg47bv.js";
import { A as ActionBar } from "./ActionBar-DPfNdSxA.js";
import { D as DropinLayout } from "./DropinLayout-CBP_cHLC.js";
import { E as EntityAssociation } from "./EntityAssociation-BABkwZ5a.js";
const alertHeader = "adyen-kyc-alert-header";
const styles = {
  alertHeader
};
const isPrimaryPartner = (member) => member?.roles?.includes("primaryPartner");
const isMemberMissingOwner = (member) => {
  return !isPrimaryPartner(member) && member.legalEntityType === LegalEntityTypes.ORGANIZATION && !member.ownerId;
};
const UnincorporatedPartnershipMembersOverview = ({
  navigateBackToTaskList,
  navigateToEditMember,
  navigateToEditMemberOwner
}) => {
  const { t, i18n } = useTranslation(["unincorpPartnership", "common"]);
  const { data: rootLe } = useLegalEntity(ROOT_LE);
  const { data: partnershipLe, refetch: refetchPartnership } = useAssociatedLegalEntity(
    rootLe,
    LegalEntityTypes.UNINCORPORATED_PARTNERSHIP
  );
  const partnershipMembers = useUnincorporatedPartnershipMembers();
  const { mutateAsync: updateLegalEntity } = useUpdateLegalEntity();
  const { setUnincorporatedPartnershipMembers } = useGlobalStore();
  addResourceBundles(i18n, [
    { ns: "unincorpPartnership", importFn: (lang) => __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "../../language/bg-BG.json": () => import("./bg-BG-er0t4jTs.js"), "../../language/cs-CZ.json": () => import("./cs-CZ-CQNBae2b.js"), "../../language/da-DK.json": () => import("./da-DK-gnPgzwrG.js"), "../../language/de-DE.json": () => import("./de-DE-D3lLuF8z.js"), "../../language/el-GR.json": () => import("./el-GR-XRux2Wpv.js"), "../../language/en-US.json": () => import("./en-US-B96dpVon.js"), "../../language/es-ES.json": () => import("./es-ES-CXDJLKAI.js"), "../../language/et-EE.json": () => import("./et-EE--cL_YqWe.js"), "../../language/fi-FI.json": () => import("./fi-FI-fArobrt5.js"), "../../language/fr-FR.json": () => import("./fr-FR-CiwkAb3E.js"), "../../language/hr-HR.json": () => import("./hr-HR-DtfHQVe0.js"), "../../language/hu-HU.json": () => import("./hu-HU-I4-KFzvz.js"), "../../language/it-IT.json": () => import("./it-IT-DIbH-udG.js"), "../../language/ja-JP.json": () => import("./ja-JP-bz7ekGnF.js"), "../../language/lt-LT.json": () => import("./lt-LT-BLsIcCtE.js"), "../../language/lv-LV.json": () => import("./lv-LV-C7hMdPcY.js"), "../../language/nl-NL.json": () => import("./nl-NL-NlkjOSYi.js"), "../../language/no-NO.json": () => import("./no-NO-Crlsj6HG.js"), "../../language/pl-PL.json": () => import("./pl-PL-DYxD6VJ_.js"), "../../language/pt-BR.json": () => import("./pt-BR-BfxgHKY4.js"), "../../language/pt-PT.json": () => import("./pt-PT-TKg5FLat.js"), "../../language/ro-RO.json": () => import("./ro-RO-3rOfS17N.js"), "../../language/sk-SK.json": () => import("./sk-SK-CjrLvDMx.js"), "../../language/sl-SI.json": () => import("./sl-SI-C-C-KJCX.js"), "../../language/sv-SE.json": () => import("./sv-SE-BHfydid5.js") }), `../../language/${lang}.json`, 4) }
  ]);
  useEffect(
    () => setUnincorporatedPartnershipMembers(partnershipMembers),
    [partnershipMembers, setUnincorporatedPartnershipMembers]
  );
  const getTaskStatus = useGetTaskStatus();
  if (!rootLe || !partnershipLe) {
    return /* @__PURE__ */ jsx(Loader, { size: "large" });
  }
  const deleteMember = async (member) => {
    try {
      await deleteUnincorporatedPartnershipMember({
        associatedMember: member,
        unincorporatedPartnership: partnershipLe,
        updateLegalEntity
      });
      await refetchPartnership();
    } catch (error) {
      console.error(error);
    }
  };
  const getActions = (member) => {
    const baseActions = [
      {
        icon: "edit",
        onSelect: () => navigateToEditMember(member),
        label: t(($) => $["editTrustMember"], {
          trustMember: member.name
        })
      }
    ];
    if (member.legalEntityType === LegalEntityTypes.ORGANIZATION && !isPrimaryPartner(member)) {
      const missingOwner = isMemberMissingOwner(member);
      baseActions.push({
        icon: missingOwner ? "plus" : "edit",
        onSelect: () => navigateToEditMemberOwner(member?.ownerId, member?.legalEntityId),
        label: t(($) => $[missingOwner ? "addOwnerToTrustMember" : "editOwnerOfTrustMember"], {
          trustMember: member.name
        })
      });
    }
    if (!isPrimaryPartner(member)) {
      baseActions.push({
        icon: "bin",
        onSelect: () => deleteMember(member),
        label: t(($) => $["removeTrustMember"], {
          trustMember: member.name
        })
      });
    }
    return baseActions;
  };
  const infoContent = (member) => /* @__PURE__ */ jsx(
    Alert,
    {
      className: styles.alertHeader,
      title: /* @__PURE__ */ jsxs(Fragment, { children: [
        t(($) => $["helpUsVerifyCompany"], { ns: "common" }),
        " ",
        /* @__PURE__ */ jsx(
          Button,
          {
            onClick: (e) => {
              e.preventDefault();
              e.stopPropagation();
              navigateToEditMemberOwner(member?.ownerId, member?.legalEntityId);
            },
            variant: "link",
            children: t(($) => $["providePersonalDetailsOfOwner"])
          }
        )
      ] })
    }
  );
  return /* @__PURE__ */ jsx(
    DropinLayout,
    {
      content: /* @__PURE__ */ jsxs("div", { className: "adyen-kyc-u-width-full", children: [
        /* @__PURE__ */ jsx(
          Header,
          {
            title: t(($) => $["partnershipMembers"]),
            description: t(($) => $["partnershipMembersDescription"])
          }
        ),
        /* @__PURE__ */ jsxs(StackLayout, { children: [
          partnershipMembers.map((member) => {
            return /* @__PURE__ */ jsx(
              EntityAssociation,
              {
                types: member.roles,
                name: member.name,
                status: getTaskStatus(
                  member.legalEntityType === LegalEntityTypes.INDIVIDUAL ? TaskTypes.UNINCORPORATED_PARTNERSHIP_MEMBER_INDIVIDUAL : TaskTypes.UNINCORPORATED_PARTNERSHIP_MEMBER_COMPANY,
                  member.legalEntityId
                ),
                actions: getActions(member),
                onNavigateToEntity: () => navigateToEditMember(member),
                infoContent: isMemberMissingOwner(member) ? infoContent(member) : void 0
              },
              member.legalEntityId
            );
          }),
          /* @__PURE__ */ jsx(
            Button,
            {
              variant: "secondary",
              icon: "plus",
              onClick: () => navigateToEditMember(void 0),
              fullWidth: true,
              children: t(($) => $["addPartner"])
            }
          )
        ] }),
        /* @__PURE__ */ jsx(
          ActionBar,
          {
            onHome: navigateBackToTaskList,
            homeButtonLabel: t(($) => $["saveAndGoToOverview"], { ns: "common" })
          }
        )
      ] })
    }
  );
};
export {
  UnincorporatedPartnershipMembersOverview
};
