;
{
  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] = "3e16ae88-d729-4d2e-9fb4-4fe7b64d30cb", e._sentryDebugIdIdentifier = "sentry-dbid-3e16ae88-d729-4d2e-9fb4-4fe7b64d30cb");
  } catch (e) {
  }
}
;
import { C as CompanyTypesValues } from "./company-types-value-D_mKv5PT.js";
import { g as getLegalEntityCountry, bq as getCapabilities, o as LegalEntityTypes, aQ as hasOwnEntityAssociationOfType, a0 as CountryCodes } from "./StoreProvider-CqQrndhS.js";
import { a as allowIndividualWithoutSoleProp } from "./accountHolderUtils-cjWK2EtN.js";
import { S as SOLE_PROP_COUNTRIES } from "./Individual.rules-B5ExQGH2.js";
import { A as ALLOWED_UNINCORPORATED_PARTNERSHIP_COUNTRIES } from "./types-BSx67xBd.js";
const TRUST_COUNTRIES = [CountryCodes.Australia, CountryCodes.NewZealand];
const BUSINESS_BANK_ACCOUNT_COUNTRIES = [
  CountryCodes.UnitedStates,
  CountryCodes.UnitedKingdom,
  CountryCodes.Netherlands,
  CountryCodes.France,
  CountryCodes.Germany,
  CountryCodes.Spain,
  CountryCodes.Belgium
];
const organizationTypesToSkipCompanyStructureForm = [
  "partnershipIncorporated",
  "associationIncorporated"
];
const getBusinessType = (businessTypeItems, country, accountHolder, legalEntityType, companyTypesValue, capabilities = []) => {
  const findBusinessType = (id) => businessTypeItems[id];
  if (organizationTypesToSkipCompanyStructureForm.includes(companyTypesValue ?? "")) {
    return businessTypeItems.legalArrangement;
  }
  if (accountHolder) {
    if (["aTrust", "partnershipUnincorporated", "anAssociation"].includes(accountHolder)) {
      return businessTypeItems.legalArrangement;
    }
    return Object.values(businessTypeItems).find(
      (businessTypeItem) => businessTypeItem.accountHolder === accountHolder
    );
  }
  switch (legalEntityType) {
    case LegalEntityTypes.ORGANIZATION:
      return findBusinessType("company");
    case LegalEntityTypes.INDIVIDUAL:
      if (allowIndividualWithoutSoleProp(capabilities)) {
        return findBusinessType("individual");
      }
      if (SOLE_PROP_COUNTRIES.includes(country)) {
        return findBusinessType("soleProprietorship");
      }
      return findBusinessType("company");
  }
};
const businessTypeMetadata = {
  individual: {
    id: "individual",
    accountHolder: "myName",
    name: "individual",
    description: "youAreNotSoleProprietorAndUseBankAccount"
  },
  soleProprietorship: {
    id: "soleProprietorship",
    accountHolder: "mySoleProprietorName",
    name: "soleProprietorship",
    description: "youAreRegisteredSoleProprietorAndUseBankAccount"
  },
  company: {
    id: "company",
    accountHolder: "theCompanyIWorkFor",
    name: "company",
    description: "yourBusinessIsRegisteredAsASeparateLegalEntityFromItsOwners"
  },
  legalArrangement: {
    id: "legalArrangement",
    name: "trustPartnershipOrAssociation",
    description: "youAreIndividualOrCompanyAndUseBankAccountInNameOfTrustPartnershipOrAssociation"
  }
};
const businessTypeIcons = {
  individual: "user",
  soleProprietorship: "user-business",
  company: "company-2",
  legalArrangement: "users-3"
};
const createAllowBusinessTypeOptionDecider = (country, capabilities) => (option) => {
  switch (option) {
    case "individual":
      return allowIndividualWithoutSoleProp(capabilities);
    case "soleProprietorship":
      return SOLE_PROP_COUNTRIES.includes(country);
    default:
      return true;
  }
};
const getBusinessTypeOptionsAndMetadata = (country, capabilities) => {
  const shouldAllowBusinessTypeOption = createAllowBusinessTypeOptionDecider(country, capabilities);
  const allowedBusinessTypeMetadata = {};
  Object.entries(businessTypeMetadata).forEach(([key, value]) => {
    const businessType = key;
    if (shouldAllowBusinessTypeOption(businessType)) {
      allowedBusinessTypeMetadata[businessType] = value;
    }
  });
  const adjustedBusinessTypeMetadata = {
    ...allowedBusinessTypeMetadata,
    ...!TRUST_COUNTRIES.includes(country) ? {
      legalArrangement: {
        id: "legalArrangement",
        name: "partnershipOrAssociation",
        description: "youAreIndividualOrCompanyAndUseBankAccountInNameOfPartnershipOrAssociation"
      }
    } : {}
  };
  if (capabilities?.includes("issueBankAccount") && BUSINESS_BANK_ACCOUNT_COUNTRIES.includes(country)) {
    delete adjustedBusinessTypeMetadata?.legalArrangement;
    delete adjustedBusinessTypeMetadata?.individual;
  }
  return adjustedBusinessTypeMetadata;
};
const legalArrangementMetadata = {
  aTrust: {
    id: "aTrust",
    accountHolder: "aTrust",
    name: "trust",
    description: "youAreTrusteeManagingTheTrustForBeneficiaries"
  },
  partnershipIncorporated: {
    id: "partnershipIncorporated",
    accountHolder: "theCompanyIWorkFor",
    name: "partnershipIncorporated",
    description: "partnershipIncorporatedDescription"
  },
  partnershipUnincorporated: {
    id: "partnershipUnincorporated",
    accountHolder: "anUnincorporatedPartnership",
    name: "partnershipUnincorporated",
    description: "partnershipUnincorporatedDescription"
  },
  associationIncorporated: {
    id: "associationIncorporated",
    accountHolder: "theCompanyIWorkFor",
    name: "associationIncorporated",
    description: "yourAssociationIsRegisteredItWasSetUpForNonCommercialPurpose"
  }
};
const legalArragementOptions = Object.keys(legalArrangementMetadata);
const getLegalArrangementOptions = (country) => legalArragementOptions.filter((option) => {
  if (option === "partnershipIncorporated" || option === "associationIncorporated") return true;
  if (option === "partnershipUnincorporated") {
    return ALLOWED_UNINCORPORATED_PARTNERSHIP_COUNTRIES.includes(country);
  }
  return TRUST_COUNTRIES.includes(country);
});
const useSelectionOptions = (legalEntityResponse) => {
  const country = getLegalEntityCountry(legalEntityResponse);
  const capabilities = getCapabilities(legalEntityResponse);
  const adjustedBusinessTypeMetadata = getBusinessTypeOptionsAndMetadata(country, capabilities);
  const legalArrangementOptions = getLegalArrangementOptions(country);
  return {
    adjustedBusinessTypeMetadata,
    legalArrangementOptions
  };
};
const mapLegalArrangementOptionToCompanyTypesValue = (legalArrangement) => {
  switch (legalArrangement) {
    case "partnershipIncorporated":
      return CompanyTypesValues.INCORPORATED_PARTNERSHIP;
    case "associationIncorporated":
      return CompanyTypesValues.INCORPORATED_ASSOCIATION;
    default:
      return void 0;
  }
};
const determineOrganizationTypeToUpdate = (targetLegalArrangement, currentCompanyTypeValue) => {
  if (targetLegalArrangement === "aTrust") {
    return;
  }
  if (!targetLegalArrangement) {
    const isUnavailableTypesInCompany = currentCompanyTypeValue === CompanyTypesValues.INCORPORATED_ASSOCIATION || currentCompanyTypeValue === CompanyTypesValues.INCORPORATED_PARTNERSHIP;
    if (isUnavailableTypesInCompany) {
      return CompanyTypesValues.PRIVATE_COMPANY;
    }
  }
  return mapLegalArrangementOptionToCompanyTypesValue(targetLegalArrangement);
};
const getDefaultLegalArrangementOrSuborganizationType = (legalEntityResponse, accountHolder) => {
  const entityAssociations = legalEntityResponse?.entityAssociations;
  const suborganizationType = legalEntityResponse?.organization?.type;
  const hasTrust = hasOwnEntityAssociationOfType(
    LegalEntityTypes.TRUST,
    entityAssociations,
    legalEntityResponse?.id
  );
  if (hasTrust || accountHolder === "aTrust") {
    return "aTrust";
  }
  const hasUnincorporatedPartnership = hasOwnEntityAssociationOfType(
    LegalEntityTypes.UNINCORPORATED_PARTNERSHIP,
    entityAssociations,
    legalEntityResponse?.id
  );
  if (hasUnincorporatedPartnership || accountHolder === "anUnincorporatedPartnership") {
    return "partnershipUnincorporated";
  }
  if (suborganizationType === CompanyTypesValues.INCORPORATED_PARTNERSHIP) {
    return "partnershipIncorporated";
  }
  if (suborganizationType === CompanyTypesValues.INCORPORATED_ASSOCIATION) {
    return "associationIncorporated";
  }
  return void 0;
};
const getTargetLegalEntityType = (businessType, legalArrangement, trusteeType, currentLegalEntityType) => {
  const trustOrUnincorporatedPartnership = legalArrangement === "aTrust" || legalArrangement === "partnershipUnincorporated";
  if (businessType === "legalArrangement" && trustOrUnincorporatedPartnership && trusteeType === "company" || businessType === "company") {
    return LegalEntityTypes.ORGANIZATION;
  }
  if (businessType === "legalArrangement" && trustOrUnincorporatedPartnership && trusteeType === "individual" || businessType === "individual" || businessType === "soleProprietorship") {
    return LegalEntityTypes.INDIVIDUAL;
  }
  if (legalArrangement && isLegalArrangementOrganizationSubtype(legalArrangement)) {
    return LegalEntityTypes.ORGANIZATION;
  }
  return currentLegalEntityType;
};
const isLegalArrangementOrganizationSubtype = (legalArrangementOption) => legalArrangementOption === "partnershipIncorporated" || legalArrangementOption === "associationIncorporated";
export {
  getDefaultLegalArrangementOrSuborganizationType as a,
  getTargetLegalEntityType as b,
  businessTypeIcons as c,
  determineOrganizationTypeToUpdate as d,
  getBusinessType as g,
  legalArrangementMetadata as l,
  organizationTypesToSkipCompanyStructureForm as o,
  useSelectionOptions as u
};
