;
{
  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] = "3a00d819-0ce1-45d1-9298-a379fc431827", e._sentryDebugIdIdentifier = "sentry-dbid-3a00d819-0ce1-45d1-9298-a379fc431827");
  } catch (e) {
  }
}
;
import { signal } from "@preact/signals";
import { aa as useI18nContext, p as useAnalyticsContext, z as Typography, V as Button, a0 as CountryCodes, ak as reverseMapping, b7 as getNomineeFromAssociation, b8 as individualOnfidoBaseMapping, ax as DecisionMakerTypes } from "./StoreProvider-CqQrndhS.js";
import { a as mapApiScriptLocalizationToSchemaFields, b as mapAddressLocalizationToJpAddressSchema } from "./mapAddressLocalizationToJpAddressSchema-vJWbpAyq.js";
import { f as formatObject } from "./utils-DNSfZiio.js";
import { jsxs, jsx } from "preact/jsx-runtime";
import { F as Field } from "./Field-BL3Mh7gm.js";
import { T as TileGroup } from "./TileGroup-CFNn8NKj.js";
const individualFormDefaultData = signal(null);
const guidanceQuestion = "adyen-kyc-guidance-question";
const options = "adyen-kyc-options";
const styles = {
  guidanceQuestion,
  options
};
const GuidanceQuestionValues = {
  YES: "Yes",
  NO: "No"
};
const GuidanceQuestion = (props) => {
  const {
    descriptionLinkText,
    errorMessage,
    name,
    noLabel,
    onChange,
    onDescriptionLinkClick,
    question,
    value,
    yesLabel
  } = props;
  const { i18n } = useI18nContext();
  const userEvents = useAnalyticsContext();
  const handleChange = (selectedValue) => {
    userEvents.addFieldEvent("Interacted with form field", {
      actionType: "select",
      field: name,
      returnValue: selectedValue
    });
    const newValue = selectedValue || null;
    onChange(newValue);
  };
  const yesTileLabel = yesLabel ?? i18n.get("yes");
  const noTileLabel = noLabel ?? i18n.get("no");
  return /* @__PURE__ */ jsxs("div", { className: styles.guidanceQuestion, children: [
    /* @__PURE__ */ jsx(Typography, { variant: "body", el: "p", children: question }),
    descriptionLinkText && onDescriptionLinkClick && /* @__PURE__ */ jsx(Button, { variant: "link", onClick: onDescriptionLinkClick, children: descriptionLinkText }),
    /* @__PURE__ */ jsx(Field, { name, className: styles.options, children: () => /* @__PURE__ */ jsx(
      TileGroup,
      {
        allowMultiple: false,
        errorMessage,
        isHorizontal: true,
        maxSelected: 1,
        name,
        onChange: handleChange,
        selected: value || "",
        tiles: [
          { label: yesTileLabel, value: GuidanceQuestionValues.YES },
          { label: noTileLabel, value: GuidanceQuestionValues.NO }
        ]
      }
    ) })
  ] });
};
const getOnfidoIdentityTypeToApiIdentityTypeMap = (data) => {
  const { country } = data;
  switch (country) {
    case CountryCodes.HongKong:
      return {
        passport: "passport",
        driversLicense: "driversLicense",
        proofOfIdentityCard: "nationalIdNumber"
      };
    default:
      return {
        nationalIdNumber: "nationalIdNumber",
        passport: "passport",
        driversLicense: "driversLicense",
        proofOfIdentityCard: "identityCard"
      };
  }
};
const getIndividualSchemaFromAPI = {
  ...individualOnfidoBaseMapping
};
const mapLegalEntityToIndividualOnfidoSchema = (legalEntity, isChangingType, isRoleFieldNeeded, parentLegalEntity) => {
  let individualOnfido = {
    ...formatObject(legalEntity, getIndividualSchemaFromAPI)
  };
  individualOnfido = {
    ...individualOnfido,
    basicDetails: {
      ...individualOnfido?.basicDetails,
      ...isChangingType && {
        firstName: "",
        lastName: "",
        localization: {}
      }
    },
    signatoryQuestionnaire: {
      isSignatory: isChangingType ? null : individualOnfido.signatoryQuestionnaire?.isSignatory ?? null
    },
    uboQuestionnaire: isChangingType ? {
      isOwner: null,
      isControllingPerson: null,
      isDirector: null,
      isNomineeShareholder: null,
      isNomineeDirector: null
    } : {
      isOwner: individualOnfido.uboQuestionnaire?.isOwner ?? null,
      isControllingPerson: individualOnfido.uboQuestionnaire?.isControllingPerson ?? null,
      isDirector: individualOnfido.uboQuestionnaire?.isDirector ?? null,
      isNomineeDirector: individualOnfido.uboQuestionnaire?.isNomineeDirector ?? null,
      isNomineeShareholder: individualOnfido.uboQuestionnaire?.isNomineeShareholder ?? null
    }
  };
  if (legalEntity?.documentDetails?.length) {
    individualOnfido = {
      ...individualOnfido,
      idVerificationMethod: {
        // Manually set verification method for existing document journey
        idVerificationMethod: "existingDocument",
        idDocument: mapDocumentDetailToIdDocument(legalEntity.documentDetails)
      }
    };
  }
  if (legalEntity.individual?.identificationData?.type && individualOnfido.additionalPersonalDetails) {
    const apiIdentityTypeToIdentityTypeMap = reverseMapping(
      getOnfidoIdentityTypeToApiIdentityTypeMap(individualOnfido.additionalPersonalDetails)
    );
    individualOnfido.additionalPersonalDetails.typeOfIdentity = apiIdentityTypeToIdentityTypeMap[legalEntity.individual.identificationData.type];
  }
  if (legalEntity.individual?.name?.localization) {
    for (const scriptLoc of legalEntity.individual.name.localization) {
      individualOnfido.basicDetails = {
        ...individualOnfido.basicDetails,
        ...mapApiScriptLocalizationToSchemaFields(scriptLoc)
      };
    }
  }
  if (legalEntity.individual?.residentialAddress?.localization) {
    individualOnfido.additionalPersonalDetails = {
      ...individualOnfido.additionalPersonalDetails,
      ...mapAddressLocalizationToJpAddressSchema(
        legalEntity.individual.residentialAddress.localization
      )
    };
  }
  if (!parentLegalEntity?.entityAssociations) {
    return individualOnfido;
  }
  const associations = parentLegalEntity?.entityAssociations?.filter((ea) => ea.legalEntityId === legalEntity?.id) ?? [];
  if (isRoleFieldNeeded && individualOnfido.basicDetails) {
    individualOnfido.basicDetails.role = associations.map((ea) => ea.type);
    individualOnfido.basicDetails.jobTitle = associations.find(
      ({ jobTitle }) => Boolean(jobTitle)
    )?.jobTitle;
  }
  if (isRoleFieldNeeded && individualOnfido.signatoryQuestionnaire && individualOnfido.uboQuestionnaire) {
    const associationTypes = new Set(associations.map((ea) => ea.type));
    const hasAssociation = (type) => associationTypes.has(type) ? GuidanceQuestionValues.YES : GuidanceQuestionValues.NO;
    individualOnfido.signatoryQuestionnaire.isSignatory = hasAssociation(
      DecisionMakerTypes.SIGNATORY
    );
    individualOnfido.uboQuestionnaire.isOwner = hasAssociation(DecisionMakerTypes.OWNER);
    individualOnfido.uboQuestionnaire.isControllingPerson = hasAssociation(
      DecisionMakerTypes.CONTROLLING_PERSON
    );
    individualOnfido.uboQuestionnaire.isDirector = hasAssociation(DecisionMakerTypes.DIRECTOR);
    const hasNomineeAssociation = (type) => associations.some((ea) => ea.type === type && ea.nominee) ? GuidanceQuestionValues.YES : GuidanceQuestionValues.NO;
    individualOnfido.uboQuestionnaire.isNomineeDirector = hasNomineeAssociation(
      DecisionMakerTypes.DIRECTOR
    );
    individualOnfido.uboQuestionnaire.isNomineeShareholder = hasNomineeAssociation(
      DecisionMakerTypes.OWNER
    );
  }
  individualOnfido.basicDetails = getNomineeFromAssociation(
    associations,
    individualOnfido.basicDetails
  );
  return individualOnfido;
};
const mapDocumentDetailToIdDocument = (documents) => {
  const activeDocument = documents.find((document) => document.active);
  return activeDocument ? {
    idDocumentType: activeDocument.type,
    modificationDate: activeDocument.modificationDate
  } : void 0;
};
export {
  GuidanceQuestionValues as G,
  GuidanceQuestion as a,
  getOnfidoIdentityTypeToApiIdentityTypeMap as g,
  individualFormDefaultData as i,
  mapLegalEntityToIndividualOnfidoSchema as m
};
