;
{
  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] = "d2a4eb5e-c1f4-4ce7-b1f6-84956dd77cae", e._sentryDebugIdIdentifier = "sentry-dbid-d2a4eb5e-c1f4-4ce7-b1f6-84956dd77cae");
  } catch (e) {
  }
}
;
import { aa as useI18nContext, ai as isEmpty, u as useTranslation, V as Button, o as LegalEntityTypes, c as useLegalEntity, a as addResourceBundles, L as Loader, _ as __variableDynamicImportRuntimeHelper } from "./StoreProvider-CqQrndhS.js";
import { jsx, jsxs } from "preact/jsx-runtime";
import { skipToken } from "@tanstack/preact-query";
import { useParams } from "wouter-preact";
import { u as useUnincorporatedPartnershipMembers } from "./useUnincorporatedPartnershipMembers-B2WglS12.js";
import { useState } from "preact/hooks";
import { F as Field } from "./Field-BL3Mh7gm.js";
import { H as Header } from "./Header-Dt-hNg1U.js";
import { T as TileGroup } from "./TileGroup-CFNn8NKj.js";
import { U as UnincorporatedPartnershipMemberTypes } from "./unincorporated-partnership-MeN1dp53.js";
import { u as useForm } from "./useForm-BFLyeF0c.js";
import { F as FormNavigation } from "./FormNavigation-BJzGPCsX.js";
import { c as createFormUtils } from "./formUtils-CwOJPw6N.js";
import { t as trustMemberLegalEntityTypes } from "./types-0MYCUtrk.js";
import { R as RadioGroup } from "./RadioGroup-jkgDMvvX.js";
const adyenKycRoleAndTypeContainer = "adyen-kyc-adyen-kyc-role-and-type-container";
const adyenKycRoleAndTypeActionBar = "adyen-kyc-adyen-kyc-role-and-type-action-bar";
const inlineRadioGroup = "adyen-kyc-inline-radio-group";
const styles = {
  adyenKycRoleAndTypeContainer,
  adyenKycRoleAndTypeActionBar,
  inlineRadioGroup
};
const UnincorporatedPartnershipRadioGroup = ({
  memberType,
  errorMessage,
  handleChangeFor,
  value
}) => {
  const { i18n } = useI18nContext();
  return /* @__PURE__ */ jsx(
    Field,
    {
      el: "fieldset",
      name: memberType,
      label: i18n.get(
        memberType === UnincorporatedPartnershipMemberTypes.OWNER ? "ownerDescriptionAsPartner" : "controllerDescriptionAsPartner"
      ),
      className: styles.inlineRadioGroup,
      errorMessage,
      children: (childProps) => /* @__PURE__ */ jsx(
        RadioGroup,
        {
          ...childProps,
          name: memberType,
          items: [
            { id: "yes", name: "yes" },
            { id: "no", name: "no" }
          ],
          value,
          onChange: (id) => handleChangeFor(memberType)(
            id
          ),
          horizontal: true
        }
      )
    }
  );
};
const unincorporatedPartnershipRoleAndTypeValidationRules = {
  entityType: {
    modes: ["blur"],
    validate: (entityType) => !isEmpty(entityType),
    errorMessage: "fieldIsRequired"
  },
  uboThroughControl: {
    modes: ["blur"],
    validate: (value) => !!value,
    errorMessage: "fieldIsRequired"
  },
  uboThroughOwnership: {
    modes: ["blur"],
    validate: (value) => !!value,
    errorMessage: "fieldIsRequired"
  }
};
const regularForms = {
  roleAndEntityType: {
    formId: "roleAndEntityType",
    formName: "roleAndEntityType",
    fields: ["role", "entityType"]
  },
  memberDetails: {
    formId: "memberDetails",
    formName: "memberDetails"
  }
};
const leTypeCardDetails = {
  [LegalEntityTypes.INDIVIDUAL]: {
    id: "individual",
    name: "individualMember",
    description: "partnerNotABusiness"
  },
  [LegalEntityTypes.ORGANIZATION]: {
    id: "organization",
    name: "companyMember",
    description: "partnerIsABusiness"
  }
};
function getUboStatus(roles, roleType, existingMember) {
  if (!existingMember) {
    return void 0;
  }
  return roles?.includes(roleType) ? "yes" : "no";
}
function UnincorporatedPartnershipRoleAndTypeDropin({
  onNavigateToMember,
  activeMember
}) {
  const { t } = useTranslation(["common"]);
  const { t: unincorpPartnershipT } = useTranslation(["unincorpPartnership"]);
  const [shouldValidate, setShouldValidate] = useState(false);
  const activeForm = regularForms.roleAndEntityType;
  const formUtils = createFormUtils(
    {},
    t
  );
  const formsWithValidity = Object.values(regularForms).map((form) => ({
    formId: form.formId,
    formName: form.formName,
    isValid: false
  }));
  const existingMember = activeMember?.legalEntityId;
  const defaultData = {
    entityType: activeMember?.legalEntityType,
    uboThroughControl: getUboStatus(
      activeMember?.roles,
      UnincorporatedPartnershipMemberTypes.CONTROLLING_PERSON,
      existingMember
    ),
    uboThroughOwnership: getUboStatus(
      activeMember?.roles,
      UnincorporatedPartnershipMemberTypes.OWNER,
      existingMember
    )
  };
  const decideFields = (data2) => {
    if (data2.entityType === LegalEntityTypes.INDIVIDUAL) {
      return ["entityType", "uboThroughControl", "uboThroughOwnership"];
    }
    return ["entityType"];
  };
  const { data, schema, errors, fieldProblems, handleChangeFor } = useForm({
    schema: decideFields,
    rules: unincorporatedPartnershipRoleAndTypeValidationRules,
    defaultData,
    shouldValidate
  });
  const onNextClick = () => {
    if (Object.values(data).some((fieldValue) => !fieldValue) && data.entityType !== LegalEntityTypes.ORGANIZATION) {
      setShouldValidate(true);
      return;
    }
    const selectedRoles = [
      UnincorporatedPartnershipMemberTypes.SECONDARY_PARTNER
    ];
    if (data.entityType === LegalEntityTypes.INDIVIDUAL) {
      if (data.uboThroughControl === "yes") {
        selectedRoles.push(UnincorporatedPartnershipMemberTypes.CONTROLLING_PERSON);
      }
      if (data.uboThroughOwnership === "yes") {
        selectedRoles.push(UnincorporatedPartnershipMemberTypes.OWNER);
      }
    }
    onNavigateToMember({
      selectedMember: activeMember,
      selectedRoles,
      selectedEntityType: data.entityType
    });
  };
  return /* @__PURE__ */ jsxs("div", { className: styles.adyenKycRoleAndTypeContainer, children: [
    /* @__PURE__ */ jsx("div", { className: "adyen-kyc-dropin__sidebar-wrapper", children: /* @__PURE__ */ jsx(
      FormNavigation,
      {
        forms: formsWithValidity,
        activeForm: formsWithValidity.find((form) => form.formId === activeForm.formId) || formsWithValidity?.[0],
        taskName: "unincorporatedPartnershipMembers",
        gotoForm: () => {
        }
      }
    ) }),
    /* @__PURE__ */ jsxs("div", { className: "adyen-kyc-form-container", children: [
      /* @__PURE__ */ jsx(
        "div",
        {
          className: "adyen-kyc-form-wrapper",
          children: /* @__PURE__ */ jsxs("form", { className: "adyen-kyc-trust__role-and-entity-type adyen-kyc-u-width-full", children: [
            /* @__PURE__ */ jsx(
              Header,
              {
                title: t(($) => $["roleAndEntityType"]),
                description: unincorpPartnershipT(($) => $["partnerRoleDescription"])
              }
            ),
            /* @__PURE__ */ jsx(
              Field,
              {
                el: "fieldset",
                name: "entityType",
                label: formUtils.getLabel("entityType", "whatTypeOfEntityIsPartner"),
                errorMessage: formUtils.getErrorMessage("entityType", errors, fieldProblems),
                children: (childProps) => /* @__PURE__ */ jsx(
                  TileGroup,
                  {
                    ...childProps,
                    name: "entityType",
                    tiles: trustMemberLegalEntityTypes.map((option) => ({
                      value: option,
                      label: unincorpPartnershipT(($) => $[leTypeCardDetails[option].name]),
                      subTitle: unincorpPartnershipT(($) => $[leTypeCardDetails[option].description])
                    })),
                    selected: data?.entityType ?? "",
                    onChange: (value) => handleChangeFor("entityType")(
                      value
                    ),
                    isHorizontal: true,
                    "aria-required": true
                  }
                )
              }
            ),
            schema.includes("uboThroughOwnership") && /* @__PURE__ */ jsx(
              UnincorporatedPartnershipRadioGroup,
              {
                memberType: UnincorporatedPartnershipMemberTypes.OWNER,
                handleChangeFor,
                errorMessage: formUtils.getErrorMessage(
                  UnincorporatedPartnershipMemberTypes.OWNER,
                  errors,
                  fieldProblems
                ),
                value: data?.uboThroughOwnership
              }
            ),
            schema.includes("uboThroughControl") && /* @__PURE__ */ jsx(
              UnincorporatedPartnershipRadioGroup,
              {
                memberType: UnincorporatedPartnershipMemberTypes.CONTROLLING_PERSON,
                handleChangeFor,
                errorMessage: formUtils.getErrorMessage(
                  UnincorporatedPartnershipMemberTypes.CONTROLLING_PERSON,
                  errors,
                  fieldProblems
                ),
                value: data?.uboThroughControl
              }
            )
          ] })
        }
      ),
      /* @__PURE__ */ jsx("div", { className: styles.adyenKycRoleAndTypeActionBar, children: /* @__PURE__ */ jsx(Button, { onClick: onNextClick, children: t(($) => $["continue"]) }) })
    ] })
  ] });
}
function UnincorporatedPartnershipMemberRoleAndTypePage({
  memberId: memberIdProp,
  onNavigateToMember,
  navigateBack
}) {
  const routeParams = useParams();
  const memberId = memberIdProp ?? routeParams.memberId;
  const { i18n } = useTranslation();
  const { data: memberLe } = useLegalEntity(memberId || skipToken);
  const unincorporatedPartnershipMembers = useUnincorporatedPartnershipMembers();
  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`, 3) }
  ]);
  if (memberId && !memberLe) {
    return /* @__PURE__ */ jsx(Loader, {});
  }
  const unincorporatedPartnershipMember = memberId ? unincorporatedPartnershipMembers.find((tm) => tm.legalEntityId === memberId) : void 0;
  return /* @__PURE__ */ jsx(
    UnincorporatedPartnershipRoleAndTypeDropin,
    {
      activeMember: unincorporatedPartnershipMember,
      onNavigateToMember,
      navigateBack
    }
  );
}
export {
  UnincorporatedPartnershipMemberRoleAndTypePage
};
