;
{
  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] = "a1fb76a9-526b-45ce-9a03-8efdb3e150af", e._sentryDebugIdIdentifier = "sentry-dbid-a1fb76a9-526b-45ce-9a03-8efdb3e150af");
  } catch (e) {
  }
}
;
import { useEffect, useState, useMemo } from "preact/hooks";
import { u as useScenarios } from "./useScenarios-CcJjvY9u.js";
import { a0 as CountryCodes, a3 as createLogger, u as useTranslation, r as Icon } from "./StoreProvider-CqQrndhS.js";
import { signal } from "@preact/signals";
import { jsx, jsxs } from "preact/jsx-runtime";
import cx from "classnames";
import { lazy } from "preact/compat";
import { I as Image } from "./Image-C0SMWMbc.js";
class AdyenKycSdkError extends Error {
  sourceError;
  constructor(message, sourceError) {
    super(message);
    this.name = this.constructor.name;
    this.sourceError = sourceError;
    const stack = [];
    if (sourceError) {
      if (sourceError instanceof this.constructor) {
        stack.push(`${this.name}: ${sourceError.message}`);
      }
      if (sourceError.stack) {
        stack.push(sourceError.stack);
      }
    }
    this.stack = stack.join("\n");
  }
}
const payoutAccountFormat = signal("local");
const defaultPayoutAccountFormat = {
  [CountryCodes.CzechRepublic]: "iban",
  [CountryCodes.Denmark]: "local",
  [CountryCodes.Hungary]: "iban",
  [CountryCodes.Norway]: "local",
  [CountryCodes.Poland]: "local",
  [CountryCodes.Sweden]: "local",
  [CountryCodes.UnitedKingdom]: "local"
};
const useUnifyLoadingStatus = (setParentLoadingStatus, ...childLoadingStatuses) => {
  useEffect(() => {
    const loadingStatus = childLoadingStatuses.some(
      (status) => status === "loading" || status === "pending"
    ) ? "loading" : "success";
    setParentLoadingStatus(loadingStatus);
  }, [...childLoadingStatuses]);
};
const logger = createLogger();
const useScenarioConfiguration = ({
  getPayoutAccountFormatData,
  parseConfiguration,
  country,
  legalEntityType,
  instantVerificationAvailable,
  setLoadingStatus,
  existingBankAccountFormat
}) => {
  const accountFormat = payoutAccountFormat.value;
  const {
    data: scenarios,
    isLoading: scenariosIsLoading,
    isError: scenariosIsError
  } = useScenarios(country, legalEntityType);
  const [accountFormatResponse, setAccountFormatResponse] = useState();
  const configurationLoadingStatus = useMemo(() => {
    if (scenariosIsLoading) return "loading";
    if (scenariosIsError) return "error";
    if (scenarios) return "success";
    return "pending";
  }, [scenarios, scenariosIsError, scenariosIsLoading]);
  const [payoutFormatLoadingStatus, setpayoutFormatLoadingStatus] = useState("success");
  useUnifyLoadingStatus(setLoadingStatus, configurationLoadingStatus, payoutFormatLoadingStatus);
  useEffect(() => {
    if (!getPayoutAccountFormatData) return;
    setpayoutFormatLoadingStatus("loading");
    const makePayoutFormatCallAndSave = async () => {
      try {
        const response = await getPayoutAccountFormatData();
        setAccountFormatResponse(response);
        const allowedBankAccountFormats = Object.keys(response);
        if (existingBankAccountFormat && !allowedBankAccountFormats.includes(existingBankAccountFormat)) {
          throw new AdyenKycSdkError(
            `Account format, ${existingBankAccountFormat}, of transferInstrument is not in allowed formats for ${country}`
          );
        }
        const defaultAccountFormat = defaultPayoutAccountFormat[country] ?? allowedBankAccountFormats[0];
        payoutAccountFormat.value = existingBankAccountFormat ?? defaultAccountFormat;
      } catch (err) {
        logger.warn("WARNING: Payout format request failed - error:", err);
      } finally {
        setpayoutFormatLoadingStatus("success");
      }
    };
    makePayoutFormatCallAndSave().catch(logger.error);
  }, [
    country,
    getPayoutAccountFormatData,
    setpayoutFormatLoadingStatus,
    existingBankAccountFormat
  ]);
  const { fieldConfigurations, requiredFields } = useMemo(() => {
    if (!scenarios) return {};
    const payoutRequiredFields = accountFormatResponse ? accountFormatResponse[accountFormat] : void 0;
    const scenarioConfig = parseConfiguration(
      payoutRequiredFields ? {
        scenarios,
        country,
        requiredFields: payoutRequiredFields,
        bankVerificationAvailable: instantVerificationAvailable
      } : {
        scenarios,
        country,
        requiredFields: void 0,
        bankVerificationAvailable: void 0
      }
    );
    return {
      fieldConfigurations: scenarioConfig,
      requiredFields: payoutRequiredFields
    };
  }, [
    accountFormatResponse,
    accountFormat,
    scenarios,
    country,
    parseConfiguration,
    instantVerificationAvailable
  ]);
  return {
    requiredFields,
    fieldConfigurations
  };
};
const uppercase = (str) => str?.toUpperCase() ?? str;
const getDocumentGuidancePrefix = (documentType) => {
  switch (documentType) {
    case "passport":
      return "passport";
    case "driversLicense":
    case "identityCard":
      return "id";
    case "bankStatement":
    case "vatDocument":
    case "registrationDocument":
    case "proofOfAddress":
    case "proofOfResidency":
    default:
      return "document";
  }
};
const documentBlurredImage = lazy(() => import("./document-blurred-BiWap0xs.js"));
const documentCutOffImage = lazy(() => import("./document-cut-off-aQezqOif.js"));
const documentExpiredImage = lazy(() => import("./document-expired-BhBXaWWQ.js"));
const documentFrontImage = lazy(() => import("./document-front-DYuhZGeQ.js"));
const idBlurredImage = lazy(() => import("./id-blurred-B5lHEP8M.js"));
const idCutOffImage = lazy(() => import("./id-cut-off-Ba1FRzKO.js"));
const idFrontImage = lazy(() => import("./id-front-CpNWN6nG.js"));
const idGlareImage = lazy(() => import("./id-glare-DgCQON8k.js"));
const passportBlurredImage = lazy(() => import("./passport-blurred-CVG493IJ.js"));
const passportCutOffImage = lazy(() => import("./passport-cut-off-COzA_TmB.js"));
const passportFrontImage = lazy(() => import("./passport-front-WJleLixT.js"));
const passportGlareImage = lazy(() => import("./passport-glare-BP5WnJZj.js"));
const documentMap = {
  "document-blurred": documentBlurredImage,
  "document-cutoff": documentCutOffImage,
  "document-expired": documentExpiredImage,
  "document-front": documentFrontImage,
  "id-blurred": idBlurredImage,
  "id-cutoff": idCutOffImage,
  "id-front": idFrontImage,
  "id-glare": idGlareImage,
  "passport-blurred": passportBlurredImage,
  "passport-cutoff": passportCutOffImage,
  "passport-front": passportFrontImage,
  "passport-glare": passportGlareImage
};
function DocumentGuidance({ type, className }) {
  const { t } = useTranslation("ui");
  const documentGuidanceItems = useMemo(() => {
    const guidancePrefix = getDocumentGuidancePrefix(type);
    const guidanceItems = [
      { svgName: `${guidancePrefix}-front`, translationKey: "good", valid: true },
      { svgName: `${guidancePrefix}-cutoff`, translationKey: "notCutOff" },
      { svgName: `${guidancePrefix}-blurred`, translationKey: "notBlurry" },
      guidancePrefix === "document" ? { svgName: `document-expired`, translationKey: "notExpired" } : { svgName: `${guidancePrefix}-glare`, translationKey: "noGlare" }
    ];
    return type === "constitutionalDocument" ? guidanceItems.filter((item) => item.svgName !== "document-expired") : guidanceItems;
  }, [type]);
  return /* @__PURE__ */ jsx("div", { className: cx("adyen-kyc-document-guidance", className), children: /* @__PURE__ */ jsx("div", { className: "adyen-kyc-document-guidance__container", children: documentGuidanceItems.map((item) => /* @__PURE__ */ jsxs("figure", { className: "adyen-kyc-document-guidance__item", children: [
    /* @__PURE__ */ jsx(Image, { lazyLoadedImage: documentMap[item.svgName] }),
    /* @__PURE__ */ jsxs("figcaption", { className: "adyen-kyc-document-guidance__description", children: [
      item.valid ? /* @__PURE__ */ jsx(Icon, { name: "check", className: "adyen-kyc-document-guidance__icon" }) : /* @__PURE__ */ jsx(
        Icon,
        {
          name: "cross",
          className: "adyen-kyc-document-guidance__icon adyen-kyc-document-guidance__icon--invalid"
        }
      ),
      /* @__PURE__ */ jsx("span", { className: "adyen-kyc-document-guidance__description-text", children: t(($) => $[item.translationKey]) })
    ] })
  ] }, item.translationKey)) }) });
}
const getPage = ({ attachments }, pageType) => {
  if (!attachments) throw Error("Document has no attachments");
  const attachment = pageType ? attachments.find((attach) => attach.pageType === pageType) : attachments[0];
  if (!attachment) throw Error(`Attachment not found${pageType ? ` with type '${pageType}'` : ""}`);
  return attachment;
};
const getPageName = (document, pageType) => getPage(document, pageType).pageName ?? "";
const mapExistingFile = (name) => ({
  name,
  existing: true
});
export {
  AdyenKycSdkError as A,
  DocumentGuidance as D,
  getPage as a,
  useScenarioConfiguration as b,
  useUnifyLoadingStatus as c,
  getPageName as g,
  mapExistingFile as m,
  payoutAccountFormat as p,
  uppercase as u
};
