;
{
  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] = "d652c133-442d-431d-b1e0-78920a3ef514", e._sentryDebugIdIdentifier = "sentry-dbid-d652c133-442d-431d-b1e0-78920a3ef514");
  } catch (e) {
  }
}
;
import { u as useTranslation, a as addResourceBundles, _ as __variableDynamicImportRuntimeHelper, b as useApiContext, l as listify, i as isUndefinedOrNull, c as useLegalEntity, R as ROOT_LE, L as Loader, g as getLegalEntityCountry, S as SettingsProvider, Q as QueryClientProvider, A as ApiProvider, E as ExperimentsContextProvider, d as StoreProvider, e as AnalyticsProvider, I as I18nProvider, D as DebugListener, T as ToastContextProvider, f as StateProvider, n as normalizeEnvironment, F as FALLBACK_LOCALE, s as setSdkToken, h as setSdkTokenHandler } from "./StoreProvider-CqQrndhS.js";
import { AcceptTermsOfServiceComponent } from "./AcceptTermsOfServiceComponent-Cj2GqvSw.js";
import { B as BusinessFinancingComponent } from "./BusinessFinancingComponent-CX33V7nQ.js";
import { C as CreateIndividualComponent } from "./CreateIndividualComponent-HE4NLlav.js";
import { C as CreateTransferInstrumentComponent } from "./CreateTransferInstrumentComponent-DKe2lIAb.js";
import { M as ManageIndividualComponent } from "./ManageIndividualComponent-CcnCVDBu.js";
import { jsx, jsxs, Fragment } from "preact/jsx-runtime";
import { u as useSalesChannels, a as usePciStatus } from "./useSalesChannels-AHAIg4Dn.js";
import { E as EmbeddedStatus } from "./EmbeddedStatus-DOl241T2.js";
import { M as ManageTermsOfServiceComponent } from "./ManageTermsOfServiceComponent-C-NMP1xI.js";
import { M as ManageTransferInstrumentComponent } from "./ManageTransferInstrumentComponent-Df7W6e7W.js";
import { O as OnboardingDropinComponent } from "./OnboardingDropinComponent-CRXiG75O.js";
import { SignPCIComponent } from "./SignPCIComponent-BnLelZrT.js";
import { V as ViewVerificationStatusComponent } from "./ViewVerificationStatusComponent-Dt_B8b0x.js";
import { H as Header } from "./Header-Dt-hNg1U.js";
import { u as useAllowedCountries } from "./mapJpAddressSchemaToAddressLocalizations-C9oJGksz.js";
import { u as useDataset } from "./useDataset-DgIHjoGg.js";
import { A as AlertIcon } from "./Alert-CpDg47bv.js";
import { D as DropinLayout } from "./DropinLayout-CBP_cHLC.js";
import { d as datasetIdentifier } from "./datasetUtil-BHQp0-xL.js";
import { render } from "preact";
import { u as uuidv4 } from "./useId-BZ0PA7jP.js";
function ManagePCIComponent({ legalEntityId, onClick }) {
  const { i18n, t } = useTranslation(["common", "contract"]);
  addResourceBundles(i18n, [
    { ns: "common", importFn: (lang) => __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "../../../language/locales/bg-BG.json": () => import("./bg-BG-6XzbmxcW.js"), "../../../language/locales/cs-CZ.json": () => import("./cs-CZ-C6vEQ8P9.js"), "../../../language/locales/da-DK.json": () => import("./da-DK-DzcTI92X.js"), "../../../language/locales/de-DE.json": () => import("./de-DE-dPfrbCii.js"), "../../../language/locales/el-GR.json": () => import("./el-GR-Dazirlmt.js"), "../../../language/locales/en-US.instructions.json": () => import("./en-US.instructions-Ddr7AO05.js"), "../../../language/locales/en-US.json": () => import("./StoreProvider-CqQrndhS.js").then((n) => n.bF), "../../../language/locales/es-ES.json": () => import("./es-ES--IvNed_Q.js"), "../../../language/locales/et-EE.json": () => import("./et-EE-CsTXSlnY.js"), "../../../language/locales/fi-FI.json": () => import("./fi-FI-BUixKfXH.js"), "../../../language/locales/fr-FR.json": () => import("./fr-FR-BM-qNLci.js"), "../../../language/locales/hr-HR.json": () => import("./hr-HR-BF74vdPD.js"), "../../../language/locales/hu-HU.json": () => import("./hu-HU-DYhMVR_c.js"), "../../../language/locales/it-IT.json": () => import("./it-IT-D63gRTDc.js"), "../../../language/locales/ja-JP.json": () => import("./ja-JP-DL0IjTzn.js"), "../../../language/locales/lt-LT.json": () => import("./lt-LT-BX8dOAzK.js"), "../../../language/locales/lv-LV.json": () => import("./lv-LV-dA8yYdKe.js"), "../../../language/locales/nl-NL.json": () => import("./nl-NL-KQ6bciOb.js"), "../../../language/locales/no-NO.json": () => import("./no-NO-Ds3VioxT.js"), "../../../language/locales/pl-PL.json": () => import("./pl-PL-BgbxWHGE.js"), "../../../language/locales/pt-BR.json": () => import("./pt-BR-Ct4s4jXV.js"), "../../../language/locales/pt-PT.json": () => import("./pt-PT-DBEsmXQX.js"), "../../../language/locales/ro-RO.json": () => import("./ro-RO-C00Ig8CL.js"), "../../../language/locales/sk-SK.json": () => import("./sk-SK-BbJWayDh.js"), "../../../language/locales/sl-SI.json": () => import("./sl-SI-hxwQIw_i.js"), "../../../language/locales/sv-SE.json": () => import("./sv-SE-0PQ-U1u6.js") }), `../../../language/locales/${lang}.json`, 6) },
    { ns: "contract", importFn: (lang) => __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "../../Contract/language/bg-BG.json": () => import("./bg-BG-K7feXvEc.js"), "../../Contract/language/cs-CZ.json": () => import("./cs-CZ-CYQO0o5V.js"), "../../Contract/language/da-DK.json": () => import("./da-DK-CGWvmdkq.js"), "../../Contract/language/de-DE.json": () => import("./de-DE-DHDJhahG.js"), "../../Contract/language/el-GR.json": () => import("./el-GR-DHNlnOwf.js"), "../../Contract/language/en-US.json": () => import("./en-US-DoiQhi0j.js"), "../../Contract/language/es-ES.json": () => import("./es-ES-CxnsKEh4.js"), "../../Contract/language/et-EE.json": () => import("./et-EE-BQixWUEV.js"), "../../Contract/language/fi-FI.json": () => import("./fi-FI-57-xkioo.js"), "../../Contract/language/fr-FR.json": () => import("./fr-FR-BxiX8Zfi.js"), "../../Contract/language/hr-HR.json": () => import("./hr-HR-BynZTNSB.js"), "../../Contract/language/hu-HU.json": () => import("./hu-HU-BtRIDozk.js"), "../../Contract/language/it-IT.json": () => import("./it-IT-masgjk9F.js"), "../../Contract/language/ja-JP.json": () => import("./ja-JP-vv3-YsHU.js"), "../../Contract/language/lt-LT.json": () => import("./lt-LT-2BMif2Bk.js"), "../../Contract/language/lv-LV.json": () => import("./lv-LV-CHdEDRVO.js"), "../../Contract/language/nl-NL.json": () => import("./nl-NL-D1b5RUJ0.js"), "../../Contract/language/no-NO.json": () => import("./no-NO-Dkh4SWbB.js"), "../../Contract/language/pl-PL.json": () => import("./pl-PL-BkGihn5Q.js"), "../../Contract/language/pt-BR.json": () => import("./pt-BR-BRdIEO2O.js"), "../../Contract/language/pt-PT.json": () => import("./pt-PT-BfL7qUzo.js"), "../../Contract/language/ro-RO.json": () => import("./ro-RO-C2yBVFht.js"), "../../Contract/language/sk-SK.json": () => import("./sk-SK-C74EF23u.js"), "../../Contract/language/sl-SI.json": () => import("./sl-SI-CvUzNn9Z.js"), "../../Contract/language/sv-SE.json": () => import("./sv-SE-BsLkPEzn.js") }), `../../Contract/language/${lang}.json`, 5) }
  ]);
  const additionalSalesChannels = useSalesChannels();
  const { data, isLoading } = usePciStatus({ additionalSalesChannels });
  const { rootLegalEntityId: currentLegalEntityId } = useApiContext();
  currentLegalEntityId.value = legalEntityId;
  const title = t(($) => $["pciDssQuestionnaire"], { ns: "contract" });
  return data?.signingRequired ? /* @__PURE__ */ jsx(
    EmbeddedStatus,
    {
      onClick,
      actionIndicator: { text: t(($) => $["sign"]) },
      title,
      loading: isLoading
    }
  ) : /* @__PURE__ */ jsx(
    EmbeddedStatus,
    {
      onClick,
      title,
      tag: { text: t(($) => $["complete"]), variant: "green" },
      loading: isLoading
    }
  );
}
const componentsMap = {
  createTransferInstrumentComponent: CreateTransferInstrumentComponent,
  createIndividualComponent: CreateIndividualComponent,
  manageTransferInstrumentComponent: ManageTransferInstrumentComponent,
  onboardingDropinComponent: OnboardingDropinComponent,
  manageIndividualComponent: ManageIndividualComponent,
  acceptTermsOfServiceComponent: AcceptTermsOfServiceComponent,
  manageTermsOfServiceComponent: ManageTermsOfServiceComponent,
  managePCIComponent: ManagePCIComponent,
  signPCIComponent: SignPCIComponent,
  viewVerificationStatusComponent: ViewVerificationStatusComponent,
  businessFinancingComponent: BusinessFinancingComponent
};
const createTransferInstrumentComponentSchema = {
  onSubmitSuccess: { type: "function" },
  legalEntityId: { type: "string", required: true },
  modalView: { type: "boolean" }
};
const manageTransferInstrumentComponentSchema = {
  onAdd: { type: "function" },
  onEdit: { type: "function" },
  onRemoveSuccess: { type: "function" },
  onInitiateRemove: { type: "function" },
  legalEntityId: { type: "string", required: true }
};
const createIndividualComponentSchema = {
  onSubmitSuccess: { type: "function" },
  legalEntityId: { type: "string" }
};
const manageIndividualComponentSchema = {
  legalEntityId: { type: "string" }
};
const acceptTermsOfServiceComponentSchema = {
  legalEntityId: { type: "string" },
  modalView: { type: "boolean" }
};
const manageTermsOfServiceComponentSchema = {
  legalEntityId: { type: "string" }
};
const managePCIComponentSchema = {
  legalEntityId: { type: "string" }
};
const signPCIComponentSchema = {
  modalView: { type: "boolean" }
};
const viewVerificationStatusComponentSchema = {
  legalEntityId: { type: "string", required: true },
  hideExplanation: { type: "boolean" },
  redirectTarget: { type: "string", exactValue: ["_self", "_blank"] },
  themeId: { type: "string" },
  onStatusChange: { type: "function" },
  onError: { type: "function" },
  onRedirect: { type: "function" },
  returnUrl: { type: "string" }
};
const onboardingDropinComponentSchema = {
  legalEntityId: { type: "string", required: true },
  openBankingPartnerConfigId: { type: "string" }
};
const businessFinancingComponentSchema = {
  legalEntityId: { type: "string", required: true },
  onSubmitSuccess: { type: "function" }
};
const componentsSchemaMap = {
  manageTransferInstrumentComponent: manageTransferInstrumentComponentSchema,
  createIndividualComponent: createIndividualComponentSchema,
  manageIndividualComponent: manageIndividualComponentSchema,
  acceptTermsOfServiceComponent: acceptTermsOfServiceComponentSchema,
  manageTermsOfServiceComponent: manageTermsOfServiceComponentSchema,
  managePCIComponent: managePCIComponentSchema,
  signPCIComponent: signPCIComponentSchema,
  createTransferInstrumentComponent: createTransferInstrumentComponentSchema,
  viewVerificationStatusComponent: viewVerificationStatusComponentSchema,
  businessFinancingComponent: businessFinancingComponentSchema,
  onboardingDropinComponent: onboardingDropinComponentSchema
};
const validateComponentName = (componentName) => {
  if (!componentName) {
    throw new Error(`

 No form Component was passed!

- For more information please check: https://github.com/Adyen/adyen-kyc-components#adyenkyccreatedropincomponentname-componentname-options-options
        `);
  }
  const form = componentsMap[componentName];
  const formsKeys = Object.keys(componentsSchemaMap);
  if (!form) {
    throw new Error(`

"${componentName}" is not a valid form Component. Please enter one of the following:
- ${listify(
      formsKeys
    )}.
        `);
  }
};
const validateCoreOptions = (coreOptions) => {
  const requiredOptions = ["locale", "environment", "country"];
  const missing = requiredOptions.filter((option) => !coreOptions[option]);
  if (!(coreOptions.sdkToken && coreOptions.getSdkToken)) {
    throw new Error(
      `

Missing or invalid parameters. Specify the sdkToken and getSdkToken your in request to initialize the component.`
    );
  }
  if (missing.length > 0) {
    throw new Error(
      `

Missing or invalid parameters. Specify ${listify(
        missing
      )} in your request to initialize the component.`
    );
  }
};
const validateComponentOptions = (componentName, options) => {
  const propertiesSchema = componentsSchemaMap[componentName];
  if (!isUndefinedOrNull(propertiesSchema)) {
    const schemaParentsPaths = [];
    validateOptionsSchema({ expected: propertiesSchema, received: options, schemaParentsPaths });
  }
};
const validateOptionsSchema = ({
  expected,
  received,
  schemaParentsPaths
}) => {
  Object.entries(expected).forEach((entry) => {
    const [propKey, validations] = entry;
    const { type, required } = validations;
    const receivedValue = received[propKey];
    if (required && isUndefinedOrNull(receivedValue)) {
      throw new Error(`

"${propKey}"${schemaParentsPaths.length > 0 ? ` inside "${schemaParentsPaths.join(" -> ")}"` : ""} is required, Please add it to the form creation options

- For more information please check: https://github.com/Adyen/adyen-kyc-components#adyenkyccreatedropincomponentname-componentname-options-options.
        `);
    }
    if (required || !required && !isUndefinedOrNull(receivedValue)) {
      if (type === "array" && !Array.isArray(receivedValue)) {
        throw new Error(
          `

 "${propKey}"${schemaParentsPaths.length > 0 ? ` inside "${schemaParentsPaths.join(" -> ")}"` : ""} must be an array.`
        );
      }
      if (type === "object" && validations.propertiesSchema) {
        schemaParentsPaths.push(propKey);
        validateOptionsSchema({
          expected: validations.propertiesSchema,
          received: receivedValue,
          schemaParentsPaths
        });
        schemaParentsPaths.pop();
        return;
      }
      if (type !== "array" && typeof receivedValue !== type) {
        throw new Error(
          `

 "${propKey}"${schemaParentsPaths.length > 0 ? ` inside "${schemaParentsPaths.join(" -> ")}"` : ""} must be a ${type}.`
        );
      }
      if (type !== "object" && validations.exactValue && !Array.isArray(validations.exactValue)) {
        if (validations.exactValue !== receivedValue) {
          throw new Error(
            `

 "${propKey}"${schemaParentsPaths.length > 0 ? ` inside "${schemaParentsPaths.join(" -> ")}"` : ""} value should be equal to "${validations.exactValue}".`
          );
        }
      }
      if (type !== "object" && validations.exactValue && Array.isArray(validations.exactValue)) {
        if (!validations.exactValue.includes(receivedValue)) {
          throw new Error(
            `

 "${propKey}" ${schemaParentsPaths.length > 0 ? ` inside "${schemaParentsPaths.join(" -> ")}"` : ""} value should be equal to one of: "${listify(validations.exactValue, {
              type: "disjunction"
            })}"`
          );
        }
      }
    }
  });
};
const validateForComponent = (componentName, options) => {
  validateComponentName(componentName);
  validateComponentOptions(componentName, options);
};
const AllowedCountryGate = ({ children }) => {
  const allowedCountries = useAllowedCountries();
  const { t } = useTranslation("common");
  const { data: rootLegalEntity } = useLegalEntity(ROOT_LE);
  const { dataset: countries } = useDataset(datasetIdentifier.country);
  if (!rootLegalEntity || !allowedCountries) return /* @__PURE__ */ jsx(Loader, {});
  const country = getLegalEntityCountry(rootLegalEntity);
  const isAllowed = allowedCountries.includes(country);
  const countryName = countries.find(({ id }) => id === country)?.name ?? country;
  if (!isAllowed)
    return /* @__PURE__ */ jsx(
      DropinLayout,
      {
        content: /* @__PURE__ */ jsxs("div", { children: [
          /* @__PURE__ */ jsx(AlertIcon, { variant: "error" }),
          /* @__PURE__ */ jsx(Header, { title: t(($) => $["countryNotSupported"]) }),
          /* @__PURE__ */ jsx("span", { children: t(($) => $["weDontSupportOnboardingInCountry"], { country: countryName }) })
        ] })
      }
    );
  return /* @__PURE__ */ jsx(Fragment, { children });
};
class AbstractEventEmitter {
  listeners = {};
  getListeners(eventName) {
    if (!this.listeners[eventName]) {
      this.listeners[eventName] = [];
    }
    return this.listeners[eventName];
  }
  on = (eventName, listener) => {
    this.getListeners(eventName).push(listener);
  };
  off = (eventName, toRemove) => {
    this.listeners[eventName] = this.getListeners(eventName).filter(
      (listener) => listener !== toRemove
    );
  };
  emit = (eventName, ...data) => {
    this.getListeners(eventName).forEach((listener) => listener(data[0]));
  };
}
class EventEmitter extends AbstractEventEmitter {
}
class BaseElement {
  _id = `${this.constructor.name}-${uuidv4()}`;
  props;
  _node;
  _component;
  eventEmitter = new EventEmitter();
  _parentInstance;
  constructor(props) {
    this.props = { ...props };
    this._parentInstance = this.props._parentInstance;
    this.remove = this.remove.bind(this);
  }
  /**
   * Mounts an element into the dom
   * @param domNode - Node (or selector) where we will mount the payment element
   * @returns this - the payment element instance we mounted
   */
  mount(domNode) {
    const node = typeof domNode === "string" ? document.querySelector(domNode) : domNode;
    if (!node) {
      throw new Error("Component could not mount. Root node was not found.");
    }
    if (this._node) {
      throw new Error("Component is already mounted.");
    }
    this._node = node;
    this._component = this.render();
    render(this._component, node);
    return this;
  }
  /**
   * Updates props, resets the internal state and remounts the element.
   * @param props - props to update
   * @returns this - the element instance
   */
  update(props) {
    this.props = { ...this.props, ...props };
    return this.remount();
  }
  updateLocale({ locale }) {
    this.eventEmitter.emit("updateLocale", locale);
  }
  updateExpiry({ expiry }) {
    this.eventEmitter.emit("updateExpiry", expiry);
  }
  /**
   * Unmounts an element and mounts it again on the same node
   */
  remount() {
    if (!this._node) {
      throw new Error("Component is not mounted.");
    }
    const storedNode = this._node;
    this.unmount();
    this.mount(storedNode);
    return this;
  }
  /**
   * Unmounts a payment element from the DOM
   */
  unmount() {
    if (this._node) {
      render(null, this._node);
    }
    this._node = void 0;
    return this;
  }
  /**
   * Unmounts an element and removes it from the parent instance
   */
  remove() {
    this.unmount();
    if (this._parentInstance) {
      this._parentInstance.remove(this);
    }
  }
}
class UIElement extends BaseElement {
  render = () => {
    const UIElement2 = this.props.component;
    return /* @__PURE__ */ jsx(SettingsProvider, { settings: this.props.settings, children: /* @__PURE__ */ jsx(QueryClientProvider, { children: /* @__PURE__ */ jsx(
      ApiProvider,
      {
        rootLegalEntityId: this.props.componentProps.legalEntityId,
        baseUrl: this.props.baseUrl,
        children: /* @__PURE__ */ jsx(
          ExperimentsContextProvider,
          {
            experiments: this.props.experiments,
            refreshExperiments: this.props.refreshExperiments,
            children: /* @__PURE__ */ jsxs(StoreProvider, { children: [
              /* @__PURE__ */ jsx("span", { className: "adyen-kyc__sdk-version", hidden: true, children: "3.95.1" }),
              /* @__PURE__ */ jsx(
                AnalyticsProvider,
                {
                  componentName: this.props.componentName,
                  rootLegalEntityId: this.props.componentProps.legalEntityId,
                  children: /* @__PURE__ */ jsx(AllowedCountryGate, { children: /* @__PURE__ */ jsxs(I18nProvider, { locale: this.props.locale, eventEmitter: this.eventEmitter, children: [
                    /* @__PURE__ */ jsx(DebugListener, {}),
                    /* @__PURE__ */ jsx("div", { className: "adyen-kyc-ui-element-container-wrapper", children: /* @__PURE__ */ jsx("div", { className: "adyen-kyc-ui-element-container", children: /* @__PURE__ */ jsx(ToastContextProvider, { children: /* @__PURE__ */ jsx(StateProvider, { children: /* @__PURE__ */ jsx(UIElement2, { ...this.props.componentProps, onUnmount: this.remove }) }) }) }) })
                  ] }) })
                }
              )
            ] })
          }
        )
      }
    ) }) });
  };
}
class Core {
  options;
  components = [];
  constructor(coreOptions) {
    this.options = this.getUpdatedOptions(coreOptions);
    this.initializeSession();
  }
  create = (componentName, componentOptions) => {
    validateForComponent(componentName, componentOptions);
    const component = componentsMap[componentName];
    const mergedOptions = {
      ...this.options,
      ...componentOptions
    };
    const uiElement = new UIElement({
      ...mergedOptions,
      component,
      componentProps: mergedOptions,
      componentName
    });
    this.components.push(uiElement);
    return uiElement;
  };
  /**
   * Updates global configurations, resets the internal state and remounts each element.
   * @param options - props to update
   * @returns this - the element instance
   */
  update = (options) => {
    this.options = this.getUpdatedOptions(options);
    this.components.forEach((c) => c.update(this.options));
    return this;
  };
  updateLocale = ({ locale }) => {
    this.options = this.getUpdatedOptions({ locale });
    this.components.forEach((c) => c.updateLocale(this.options));
    return this;
  };
  updateExpiry = ({ expiry }) => {
    this.options = this.getUpdatedOptions({ expiry });
    this.components.forEach((c) => c.updateExpiry(this.options));
    return this;
  };
  /**
   * Remove the reference of a component
   * @param component - reference to the component to be removed
   * @returns this - the element instance
   */
  remove = (component) => {
    this.components = this.components.filter((c) => c._id !== component._id);
    component.unmount();
    return this;
  };
  getUpdatedOptions = (options) => {
    const newOptions = { ...this.options, ...options };
    validateCoreOptions(newOptions);
    newOptions.baseUrl = normalizeEnvironment(newOptions.environment);
    if (!newOptions.locale) newOptions.locale = FALLBACK_LOCALE;
    return newOptions;
  };
  initializeSession = () => {
    if (this.options.sdkToken && this.options.getSdkToken) {
      setSdkToken(this.options.sdkToken);
      setSdkTokenHandler(this.options.getSdkToken);
    }
  };
}
if (CSS.supports("container", "foo / inline-size") === false) {
  import("container-query-polyfill");
}
export {
  Core as default
};
