;
{
  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] = "6f3b4219-5aab-4ab0-b8dc-c42c533d5de7", e._sentryDebugIdIdentifier = "sentry-dbid-6f3b4219-5aab-4ab0-b8dc-c42c533d5de7");
  } catch (e) {
  }
}
;
import { a0 as CountryCodes, ax as DecisionMakerTypes, j as TaskTypes, g as getLegalEntityCountry, bc as getAvailableDecisionMakerRoleTypes, bd as allowedCountriesForNominee, ay as Scenarios, be as isLowRiskCountry } from "./StoreProvider-CqQrndhS.js";
import { g as getAddressSchemaForCountry, C as COUNTRIES_WITH_STATES_DATASET } from "./utils-DmjdHPet.js";
import { c as createFormRules } from "./form-rules-DhbF2mY4.js";
import { i as isJapanLocalizationEnabled } from "./japanSupportUtils-BUJ_9m0k.js";
import { i as isBafinSignatoryFlow } from "./bafinUtils-5hCwQF0u.js";
import { g as getLocalizedIdDocumentTypeOptions } from "./utils-DIFjlEiz.js";
const REQUIRED = "REQUIRED";
const OPTIONAL = "OPTIONAL";
const ID_NUMBER_EXEMPT_COUNTRIES = [
  CountryCodes.Canada,
  CountryCodes.PuertoRico,
  CountryCodes.UnitedStates
];
const COUNTRIES_WHICH_USE_MULTIPLE_IDENTITY_TYPES = [
  CountryCodes.HongKong,
  CountryCodes.Australia,
  CountryCodes.NewZealand
];
const ID_NUMBER_REQUIRED_FOR_DIRECTOR_COUNTRIES = [
  CountryCodes.Singapore,
  CountryCodes.UnitedStates
];
const NATIONALITY_REQUIRED_FOR_COUNTRIES = [
  CountryCodes.Singapore,
  CountryCodes.HongKong
];
const JOB_TITLE_REQUIRED_FOR_COUNTRIES = [CountryCodes.NewZealand];
const ISSUER_REQUIRED_FOR_COUNTRIES = [CountryCodes.Australia];
const EXPIRY_DATE_REQUIRED_FOR_COUNTRIES = [CountryCodes.NewZealand];
const LICENSE_CARD_NUMBER_REQUIRED_FOR_COUNTRIES = [
  CountryCodes.NewZealand,
  CountryCodes.Australia
];
const TAX_ID_REQUIRED_COUNTRIES = [
  CountryCodes.Austria,
  CountryCodes.Belgium,
  CountryCodes.Croatia,
  CountryCodes.Cyprus,
  CountryCodes.Estonia,
  CountryCodes.Finland,
  CountryCodes.France,
  CountryCodes.Germany,
  CountryCodes.Greece,
  CountryCodes.Ireland,
  CountryCodes.Latvia,
  CountryCodes.Lithuania,
  CountryCodes.Luxembourg,
  CountryCodes.Malta,
  CountryCodes.Netherlands,
  CountryCodes.Portugal,
  CountryCodes.Slovakia,
  CountryCodes.Slovenia,
  CountryCodes.UnitedKingdom
];
const SOLE_PROP_COUNTRIES = [
  CountryCodes.Austria,
  CountryCodes.Australia,
  CountryCodes.Belgium,
  CountryCodes.Bulgaria,
  CountryCodes.Canada,
  CountryCodes.Croatia,
  CountryCodes.Cyprus,
  CountryCodes.CzechRepublic,
  CountryCodes.Denmark,
  CountryCodes.Estonia,
  CountryCodes.Finland,
  CountryCodes.France,
  CountryCodes.Germany,
  CountryCodes.Gibraltar,
  CountryCodes.Greece,
  CountryCodes.Guernsey,
  CountryCodes.HongKong,
  CountryCodes.Hungary,
  CountryCodes.Ireland,
  CountryCodes.IsleOfMan,
  CountryCodes.Italy,
  CountryCodes.Japan,
  CountryCodes.Jersey,
  CountryCodes.Latvia,
  CountryCodes.Liechtenstein,
  CountryCodes.Lithuania,
  CountryCodes.Luxembourg,
  CountryCodes.Malta,
  CountryCodes.Monaco,
  CountryCodes.Netherlands,
  CountryCodes.NewZealand,
  CountryCodes.Norway,
  CountryCodes.Poland,
  CountryCodes.Portugal,
  CountryCodes.PuertoRico,
  CountryCodes.Romania,
  CountryCodes.Singapore,
  CountryCodes.Slovakia,
  CountryCodes.Slovenia,
  CountryCodes.Spain,
  CountryCodes.Sweden,
  CountryCodes.Switzerland,
  CountryCodes.UnitedKingdom,
  CountryCodes.UnitedStates
];
const DECISION_MAKER_TYPES_WITH_JOBTITLE = [
  DecisionMakerTypes.SIGNATORY,
  DecisionMakerTypes.CONTROLLING_PERSON
];
const ID_MISSING_DATA_ERROR_CODE = "2_8071";
const REMEDIATION_CODES_UPLOAD_ID = ["1_301", "1_302", "1_303"];
const individualOnfidoRules = ({
  matchingScenario,
  data,
  country,
  taskType,
  isExperimentEnabled = () => false,
  rootLegalEntity,
  problems
}) => createFormRules({
  countryUsesTaxId: () => {
    const hasTaxScenario = matchingScenario?.includes(Scenarios.L_TAXINFO);
    if (hasTaxScenario && TAX_ID_REQUIRED_COUNTRIES.includes(country)) {
      return "REQUIRED";
    }
    return void 0;
  },
  isDirectorIdNumberRequiredForCountry: () => {
    if (!data.basicDetails?.role) {
      return REQUIRED;
    }
    if (data.basicDetails?.role?.some((role) => role !== DecisionMakerTypes.DIRECTOR)) {
      return REQUIRED;
    }
    if (ID_NUMBER_REQUIRED_FOR_DIRECTOR_COUNTRIES.includes(country) && data.basicDetails?.role?.some((role) => role === DecisionMakerTypes.DIRECTOR)) {
      return REQUIRED;
    }
  },
  idNumberRules: () => {
    const hasTaxScenario = matchingScenario?.includes(Scenarios.L_TAXINFO);
    if (data.additionalPersonalDetails?.idNumberExempt) {
      return OPTIONAL;
    }
    if (!data.basicDetails?.role) {
      return REQUIRED;
    }
    if (hasTaxScenario && country === CountryCodes.UnitedStates && data.basicDetails?.role?.every((role) => role === DecisionMakerTypes.SIGNATORY)) {
      return REQUIRED;
    }
    if (!hasTaxScenario && country === CountryCodes.UnitedStates && data.basicDetails?.role?.every((role) => role === DecisionMakerTypes.SIGNATORY)) {
      return void 0;
    }
    if (data.basicDetails?.role?.some((role) => role !== DecisionMakerTypes.DIRECTOR)) {
      return REQUIRED;
    }
    if (ID_NUMBER_REQUIRED_FOR_DIRECTOR_COUNTRIES.includes(country) && data.basicDetails?.role?.some((role) => role === DecisionMakerTypes.DIRECTOR)) {
      return REQUIRED;
    }
  },
  requiredIfDecisionMakerTask: () => {
    if (taskType === TaskTypes.DECISION_MAKER || taskType === TaskTypes.TRUST_MEMBER_COMPANY_OWNER || taskType === TaskTypes.UNINCORPORATED_PARTNERSHIP_MEMBER_COMPANY_OWNER) {
      return REQUIRED;
    }
  },
  idNumberExemptIfApplicableCountry: () => {
    if (matchingScenario?.includes(Scenarios.L_TAXINFO)) {
      return void 0;
    }
    if (country === CountryCodes.UnitedStates && data.basicDetails?.role?.every((role) => role === DecisionMakerTypes.SIGNATORY)) {
      return void 0;
    }
    if (ID_NUMBER_EXEMPT_COUNTRIES.includes(country)) {
      return REQUIRED;
    }
  },
  hasChosenIdType: () => {
    return data?.manualIdUpload?.idDocumentType ? REQUIRED : void 0;
  },
  backPageIfRequiredForIdType: () => {
    const idDocumentTypeOptions = getLocalizedIdDocumentTypeOptions(country);
    const idDocumentOption = idDocumentTypeOptions.find(
      ({ id }) => id === data.manualIdUpload?.idDocumentType
    );
    return idDocumentOption?.hasBackPage ? REQUIRED : void 0;
  },
  isProofOfResidencyRequired: () => {
    if (isBafinSignatoryFlow({ taskType, data, scenarios: matchingScenario })) {
      return void 0;
    }
    if (data.proofOfResidency?.proofOfResidency?.length) {
      return REQUIRED;
    }
    const isInstantFlow = data?.idVerificationMethod?.idVerificationMethod === "instantVerification";
    if (!isInstantFlow) {
      return void 0;
    }
    const documentCountry = data?.idVerificationMethod?.idDocument?.documentCountry;
    const residenceCountry = data?.additionalPersonalDetails?.country ?? country;
    if (!documentCountry || !residenceCountry) {
      return void 0;
    }
    const countriesMismatch = documentCountry !== residenceCountry;
    const isEeaLowRiskException = isLowRiskCountry(documentCountry) && isLowRiskCountry(residenceCountry);
    if (countriesMismatch && !isEeaLowRiskException) {
      return REQUIRED;
    }
  },
  isProofOfNationalIdRequired: () => {
    if (isBafinSignatoryFlow({ taskType, data, scenarios: matchingScenario })) {
      return void 0;
    }
    if (data.proofOfNationalId?.proofOfNationalId?.length) {
      return REQUIRED;
    }
  },
  isIdVerificationMethodRequired: () => {
    if (isBafinSignatoryFlow({ taskType, data, scenarios: matchingScenario })) {
      return void 0;
    }
    return REQUIRED;
  },
  contactsIfRequiredForRole: () => {
    if (taskType === TaskTypes.DECISION_MAKER) {
      if (data.basicDetails?.role?.includes(DecisionMakerTypes.SIGNATORY)) {
        return REQUIRED;
      }
      return;
    }
    return REQUIRED;
  },
  requiredIfPhoneScenarioDisabled: () => !isExperimentEnabled("EnablePhoneFieldScenario") ? REQUIRED : void 0,
  jobTitleIfRequiredForRole: () => {
    if (taskType !== TaskTypes.DECISION_MAKER) return;
    if (data.basicDetails?.role?.some(
      (role) => DECISION_MAKER_TYPES_WITH_JOBTITLE.includes(role)
    ) || JOB_TITLE_REQUIRED_FOR_COUNTRIES.includes(country)) {
      return REQUIRED;
    }
  },
  isPlaceOfBirthRequired: () => {
    if (isBafinSignatoryFlow({ taskType, data, scenarios: matchingScenario })) {
      return REQUIRED;
    }
  },
  nationalityIfRequiredForRole: () => {
    if (isBafinSignatoryFlow({ taskType, data, scenarios: matchingScenario })) {
      return REQUIRED;
    }
    const enableNationalitySGHK = isExperimentEnabled("EnableNationalitySGHK");
    const rootLegalEntityCountry = rootLegalEntity?.organization?.registeredAddress.country;
    if (enableNationalitySGHK && rootLegalEntityCountry && NATIONALITY_REQUIRED_FOR_COUNTRIES.includes(rootLegalEntityCountry)) {
      return REQUIRED;
    }
    if (NATIONALITY_REQUIRED_FOR_COUNTRIES.includes(country) || data?.additionalPersonalDetails?.nationality) {
      return REQUIRED;
    }
  },
  requiredIfCountryUsesMultipleTypesOfIdentity: () => {
    if (COUNTRIES_WHICH_USE_MULTIPLE_IDENTITY_TYPES.includes(country)) {
      return REQUIRED;
    }
  },
  licenseCardNumberRules: () => {
    if (data.additionalPersonalDetails?.typeOfIdentity === "driversLicense" && LICENSE_CARD_NUMBER_REQUIRED_FOR_COUNTRIES.includes(country)) {
      return REQUIRED;
    }
  },
  issuerStateRequired: () => {
    if (data.additionalPersonalDetails?.typeOfIdentity === "driversLicense" && ISSUER_REQUIRED_FOR_COUNTRIES.includes(country)) {
      return REQUIRED;
    }
  },
  expiryDateRequired: () => {
    if (data.additionalPersonalDetails?.typeOfIdentity === "passport" && EXPIRY_DATE_REQUIRED_FOR_COUNTRIES.includes(country)) {
      return REQUIRED;
    }
  },
  legalRepresentativeRelationshipRequired: () => taskType === TaskTypes.LEGAL_REPRESENTATIVE_DETAILS ? REQUIRED : void 0,
  isProofOfRelationshipRequired: () => void 0,
  // not required until more clarity from product
  addressIfRequiredForCountry: () => {
    const addressSchema = getAddressSchemaForCountry(data?.additionalPersonalDetails?.country);
    return addressSchema.includes("address") ? "REQUIRED" : void 0;
  },
  otherAddressInfoIfRequiredForCountry: () => {
    if (isJapanLocalizationEnabled(isExperimentEnabled, country)) {
      return "REQUIRED";
    }
    const addressSchema = getAddressSchemaForCountry(data?.additionalPersonalDetails?.country);
    return addressSchema.includes("otherAddressInformation") ? "OPTIONAL" : void 0;
  },
  postalCodeIfRequiredForCountry: () => {
    const addressSchema = getAddressSchemaForCountry(data?.additionalPersonalDetails?.country);
    return addressSchema.includes("postalCode") ? "REQUIRED" : void 0;
  },
  cityIfRequiredForCountry: () => {
    const addressSchema = getAddressSchemaForCountry(data?.additionalPersonalDetails?.country);
    return addressSchema.includes("city") ? "REQUIRED" : void 0;
  },
  stateOrProvinceIfRequiredForCountry: () => {
    const addressSchema = getAddressSchemaForCountry(data?.additionalPersonalDetails?.country);
    return addressSchema.includes("stateOrProvince") && COUNTRIES_WITH_STATES_DATASET.includes(data?.additionalPersonalDetails?.country ?? country) ? "REQUIRED" : void 0;
  },
  nomineeDirectorRequiredForCountry: () => {
    if (allowedCountriesForNominee.includes(data?.additionalPersonalDetails?.country ?? country) && data?.basicDetails?.role?.includes(DecisionMakerTypes.DIRECTOR)) {
      return "REQUIRED";
    }
  },
  nomineeShareHolderRequiredForCountry: () => {
    if (allowedCountriesForNominee.includes(data?.additionalPersonalDetails?.country ?? country) && data?.basicDetails?.role?.includes(DecisionMakerTypes.OWNER)) {
      return "REQUIRED";
    }
  },
  isUsingInstantVerificationOrHasExistingDocument: () => {
    if (isBafinSignatoryFlow({ taskType, data, scenarios: matchingScenario })) {
      return void 0;
    }
    const isUsingInstantVerification = data?.idVerificationMethod?.idVerificationMethod === "instantVerification";
    const existingDocument = data?.idVerificationMethod?.idDocument;
    return isUsingInstantVerification || existingDocument ? REQUIRED : void 0;
  },
  isManualIdFlow: () => {
    if (isBafinSignatoryFlow({ taskType, data, scenarios: matchingScenario })) {
      return void 0;
    }
    const isManualFlow = data?.idVerificationMethod?.idVerificationMethod === "manualVerification";
    return isManualFlow ? "REQUIRED" : void 0;
  },
  isManualIdFlowAndNotProvidingIdNumber: () => {
    if (isBafinSignatoryFlow({ taskType, data, scenarios: matchingScenario })) {
      return void 0;
    }
    const hasMissingId = problems?.missingData?.some(
      (error) => error.code === ID_MISSING_DATA_ERROR_CODE
    );
    const isManualFlow = data?.idVerificationMethod?.idVerificationMethod === "manualVerification";
    const idNumberExempt = data?.additionalPersonalDetails?.idNumberExempt;
    const hasIdRemediationAction = Object.keys(problems?.remediationActions ?? {}).some(
      (code) => REMEDIATION_CODES_UPLOAD_ID.includes(code)
    );
    return isManualFlow && (idNumberExempt || hasMissingId || hasIdRemediationAction) ? "REQUIRED" : void 0;
  },
  isManualIdFlowAndHasMissingData: () => {
    if (isBafinSignatoryFlow({ taskType, data, scenarios: matchingScenario })) {
      return void 0;
    }
    const hasMissingId = problems?.missingData?.some(
      (error) => error.code === ID_MISSING_DATA_ERROR_CODE
    );
    const hasIdRemediationAction = Object.keys(problems?.remediationActions ?? {}).some(
      (code) => REMEDIATION_CODES_UPLOAD_ID.includes(code)
    );
    const isManualFlow = data?.idVerificationMethod?.idVerificationMethod === "manualVerification";
    return isManualFlow && (hasMissingId || hasIdRemediationAction) ? "REQUIRED" : void 0;
  },
  idVerificationRequired: () => {
    return REQUIRED;
  },
  isDirectorRequiredForCountry: () => {
    const decisionMakerCountry = rootLegalEntity ? getLegalEntityCountry(rootLegalEntity) : country;
    if (getAvailableDecisionMakerRoleTypes(decisionMakerCountry, matchingScenario).some(
      (maker) => maker.roleType === DecisionMakerTypes.DIRECTOR
    )) {
      return "REQUIRED";
    }
  },
  japanSpecificField: () => {
    const targetCountry = taskType === TaskTypes.DECISION_MAKER && rootLegalEntity?.organization?.registeredAddress.country || country;
    if (isJapanLocalizationEnabled(isExperimentEnabled, targetCountry)) {
      return "REQUIRED";
    }
  }
});
export {
  COUNTRIES_WHICH_USE_MULTIPLE_IDENTITY_TYPES as C,
  DECISION_MAKER_TYPES_WITH_JOBTITLE as D,
  SOLE_PROP_COUNTRIES as S,
  individualOnfidoRules as i
};
