;
{
  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] = "8af77aac-e017-40cf-9261-f10e3f8e284c", e._sentryDebugIdIdentifier = "sentry-dbid-8af77aac-e017-40cf-9261-f10e3f8e284c");
  } catch (e) {
  }
}
;
import { j as TaskTypes, o as LegalEntityTypes, u as useTranslation, c as useLegalEntity, a as addResourceBundles, L as Loader, R as ROOT_LE, p as useAnalyticsContext, V as Button, _ as __variableDynamicImportRuntimeHelper } from "./StoreProvider-CqQrndhS.js";
import { jsxs, Fragment, jsx } from "preact/jsx-runtime";
import { useState, useEffect } from "preact/hooks";
import { S as StepProgressIndicator } from "./StepProgressIndicator-C2DPnOQi.js";
import { useMemo } from "preact/compat";
import { u as useCanSeeIntroduction, a as useLegalEntityType } from "./useCanSeeIntroduction-DgSFLMfV.js";
const IntroductionScreens = {
  PROLOGUE: "PROLOGUE",
  INDIVIDUAL: TaskTypes.INDIVIDUAL,
  DECISION_MAKER: TaskTypes.DECISION_MAKER,
  SOLE_PROPRIETOR_COMPANY: TaskTypes.SOLE_PROPRIETOR_COMPANY,
  TRUST: TaskTypes.TRUST,
  TRUST_MEMBER: TaskTypes.TRUST_MEMBER,
  ACCOUNT: "ACCOUNT",
  EPILOGUE: "EPILOGUE"
};
const introductionScreensByLegalEntityType = {
  [LegalEntityTypes.INDIVIDUAL]: [
    IntroductionScreens.PROLOGUE,
    IntroductionScreens.INDIVIDUAL,
    IntroductionScreens.ACCOUNT,
    IntroductionScreens.EPILOGUE
  ],
  [LegalEntityTypes.ORGANIZATION]: [
    IntroductionScreens.PROLOGUE,
    IntroductionScreens.DECISION_MAKER,
    IntroductionScreens.ACCOUNT,
    IntroductionScreens.EPILOGUE
  ],
  [LegalEntityTypes.SOLE_PROPRIETORSHIP]: [
    IntroductionScreens.PROLOGUE,
    IntroductionScreens.INDIVIDUAL,
    IntroductionScreens.SOLE_PROPRIETOR_COMPANY,
    IntroductionScreens.ACCOUNT,
    IntroductionScreens.EPILOGUE
  ],
  [LegalEntityTypes.TRUST]: [
    IntroductionScreens.PROLOGUE,
    IntroductionScreens.INDIVIDUAL,
    IntroductionScreens.DECISION_MAKER,
    IntroductionScreens.TRUST,
    IntroductionScreens.TRUST_MEMBER,
    IntroductionScreens.ACCOUNT,
    IntroductionScreens.EPILOGUE
  ],
  // TODO SOE-2109: Update to use Unincorporated Partnership screens
  [LegalEntityTypes.UNINCORPORATED_PARTNERSHIP]: [
    IntroductionScreens.PROLOGUE,
    IntroductionScreens.INDIVIDUAL,
    IntroductionScreens.DECISION_MAKER,
    IntroductionScreens.TRUST,
    IntroductionScreens.TRUST_MEMBER,
    IntroductionScreens.ACCOUNT,
    IntroductionScreens.EPILOGUE
  ]
};
const useIntroductionScreens = ({ legalEntity, tasks }) => {
  const canSeeIntroduction = useCanSeeIntroduction({ legalEntity });
  const legalEntityType = useLegalEntityType({ legalEntity });
  const introductionScreens = useMemo(
    () => legalEntityType ? introductionScreensByLegalEntityType[legalEntityType].filter((screen) => {
      const isAccountScreen = screen === IntroductionScreens.ACCOUNT;
      const hasAccountTask = tasks.includes(TaskTypes.PAYIN) || tasks.includes(TaskTypes.PAYOUT);
      const isSoleProprietorScreen = screen === IntroductionScreens.SOLE_PROPRIETOR_COMPANY;
      const isSoleProprietor = legalEntityType === LegalEntityTypes.SOLE_PROPRIETORSHIP;
      const isTrustScreen = screen === IntroductionScreens.TRUST || screen === IntroductionScreens.TRUST_MEMBER;
      const isTrust = legalEntityType === LegalEntityTypes.TRUST;
      if (isAccountScreen) return hasAccountTask;
      if (isSoleProprietorScreen) return isSoleProprietor;
      if (isTrustScreen) return isTrust;
      return tasks.some((task) => screen === task);
    }) : [],
    [legalEntityType, tasks]
  );
  return canSeeIntroduction && introductionScreens?.length > 0 ? [IntroductionScreens.PROLOGUE, ...introductionScreens, IntroductionScreens.EPILOGUE] : void 0;
};
const toCapitalized = (s) => `${s[0].toUpperCase()}${s.slice(1).toLowerCase()}`;
const toPascalCase = (s) => s.split(/[^A-Za-z]/).map((word) => toCapitalized(word)).join("");
const IntroductionScreenTranslationKeyElements = {
  ListItem: "LI",
  Paragraph: "P"
};
const getIntroductionScreenTranslationKeys = (factors, i18n) => {
  const introductionStrings = i18n.getResourceBundle(i18n.language, "introduction");
  if (!introductionStrings || !factors.legalEntityType) return;
  const elForKey = (factors.elementType || "").toUpperCase();
  const lForKey = toPascalCase(factors.legalEntityType || "");
  const iForKey = toPascalCase(factors.introductionScreen);
  const keyPrefix = `introductionScreen${iForKey}Description${elForKey}`;
  const keyPrefixWithL = `introductionScreen${iForKey}${lForKey}Description${elForKey}`;
  const keys = Object.keys(introductionStrings).filter((key) => key.startsWith(keyPrefix));
  const keysWithL = Object.keys(introductionStrings).filter(
    (key) => key.startsWith(keyPrefixWithL)
  );
  return (keysWithL.length ? keysWithL : keys).sort(
    (a, b) => Number(a.at(-1)) - Number(b.at(-1))
  );
};
const IntroductionScreen = ({
  introductionScreen,
  legalEntity,
  number
}) => {
  const { t, i18n } = useTranslation("introduction");
  const legalEntityType = useLegalEntityType({ legalEntity });
  const paragraphKeys = getIntroductionScreenTranslationKeys(
    {
      introductionScreen,
      legalEntityType,
      elementType: IntroductionScreenTranslationKeyElements.Paragraph
    },
    i18n
  );
  const listItemKeys = getIntroductionScreenTranslationKeys(
    {
      introductionScreen,
      legalEntityType,
      elementType: IntroductionScreenTranslationKeyElements.ListItem
    },
    i18n
  );
  return /* @__PURE__ */ jsxs(Fragment, { children: [
    /* @__PURE__ */ jsx("div", { className: "adyen-kyc-introduction__number", children: number }),
    /* @__PURE__ */ jsx("div", { className: "adyen-kyc-introduction__title", children: t(
      ($) => $[`introductionScreen${toPascalCase(introductionScreen)}Title`]
    ) }),
    /* @__PURE__ */ jsxs("div", { className: "adyen-kyc-introduction__description", children: [
      !!paragraphKeys?.length && paragraphKeys.map((key) => /* @__PURE__ */ jsx("p", { children: t(($) => $[key]) }, key)),
      !!listItemKeys?.length && /* @__PURE__ */ jsx("ul", { children: listItemKeys.map((key) => /* @__PURE__ */ jsx("li", { children: t(($) => $[key]) }, key)) })
    ] })
  ] });
};
function Introduction({ onExitIntroduction, tasks }) {
  const { data: rootLe, isLoading } = useLegalEntity(ROOT_LE);
  const { i18n } = useTranslation();
  addResourceBundles(i18n, [
    { ns: "introduction", importFn: (lang) => __variableDynamicImportRuntimeHelper(/* @__PURE__ */ Object.assign({ "../language/introduction/bg-BG.json": () => import("./bg-BG-BY3Wa361.js"), "../language/introduction/cs-CZ.json": () => import("./cs-CZ-BEFeaKsV.js"), "../language/introduction/da-DK.json": () => import("./da-DK-D6UK8XT9.js"), "../language/introduction/de-DE.json": () => import("./de-DE-DUl6gRKv.js"), "../language/introduction/el-GR.json": () => import("./el-GR-B5j7VZ3E.js"), "../language/introduction/en-US.json": () => import("./en-US-BSQXKu6d.js"), "../language/introduction/es-ES.json": () => import("./es-ES-Cavm0szq.js"), "../language/introduction/et-EE.json": () => import("./et-EE-DUWZ2Vqm.js"), "../language/introduction/fi-FI.json": () => import("./fi-FI-DVa-ccaW.js"), "../language/introduction/fr-FR.json": () => import("./fr-FR-CY9emHgF.js"), "../language/introduction/hr-HR.json": () => import("./hr-HR-CnP5sqih.js"), "../language/introduction/hu-HU.json": () => import("./hu-HU-BTlpbCpc.js"), "../language/introduction/it-IT.json": () => import("./it-IT-GgHc0cHR.js"), "../language/introduction/ja-JP.json": () => import("./ja-JP-CbgaW99b.js"), "../language/introduction/lt-LT.json": () => import("./lt-LT-DTQGR9M0.js"), "../language/introduction/lv-LV.json": () => import("./lv-LV-BQ4F1GrV.js"), "../language/introduction/nl-NL.json": () => import("./nl-NL-CUcML482.js"), "../language/introduction/no-NO.json": () => import("./no-NO-BBCvsecq.js"), "../language/introduction/pl-PL.json": () => import("./pl-PL-kGaeUP-w.js"), "../language/introduction/pt-BR.json": () => import("./pt-BR-nU_2Wbo5.js"), "../language/introduction/pt-PT.json": () => import("./pt-PT-JVqqgvPs.js"), "../language/introduction/ro-RO.json": () => import("./ro-RO-C83h2zHZ.js"), "../language/introduction/sk-SK.json": () => import("./sk-SK-CgLJIuJw.js"), "../language/introduction/sl-SI.json": () => import("./sl-SI-BzeVaC1Z.js"), "../language/introduction/sv-SE.json": () => import("./sv-SE-CVmo11gI.js") }), `../language/introduction/${lang}.json`, 4) }
  ]);
  if (isLoading || !rootLe) {
    return /* @__PURE__ */ jsx(Loader, { size: "large" });
  }
  return /* @__PURE__ */ jsx(IntroductionInner, { legalEntity: rootLe, onExitIntroduction, tasks });
}
const IntroductionInner = ({
  legalEntity,
  onExitIntroduction,
  tasks
}) => {
  const { t } = useTranslation(["common", "introduction"]);
  const userEvents = useAnalyticsContext();
  const introductionScreens = useIntroductionScreens({ legalEntity, tasks });
  const [activeIndex, setActiveIndex] = useState(0);
  const pageEventDetails = {
    page: introductionScreens?.length ? introductionScreens[activeIndex] : void 0
  };
  useEffect(() => {
    userEvents.addTaskEvent("Landed on page", {
      actionType: "start"
    });
  }, [userEvents]);
  useEffect(() => {
    if (!introductionScreens?.length) {
      onExitIntroduction();
    }
  }, [introductionScreens, onExitIntroduction]);
  return introductionScreens?.length ? /* @__PURE__ */ jsxs("div", { className: "adyen-kyc-introduction", children: [
    /* @__PURE__ */ jsx(
      StepProgressIndicator,
      {
        activeStepIndex: activeIndex + 1,
        stepsCount: introductionScreens.length
      }
    ),
    /* @__PURE__ */ jsx("div", { className: "adyen-kyc-introduction__skip", children: /* @__PURE__ */ jsx(
      Button,
      {
        onClick: () => {
          userEvents.addPageEvent("Clicked button", {
            ...pageEventDetails,
            actionType: "skip",
            label: "goToOverviewFromIntroduction"
          });
          onExitIntroduction();
        },
        variant: "link",
        children: t(($) => $["goToOverviewFromIntroduction"], { ns: "introduction" })
      }
    ) }),
    /* @__PURE__ */ jsx(
      IntroductionScreen,
      {
        introductionScreen: introductionScreens[activeIndex],
        legalEntity,
        number: activeIndex > 0 && activeIndex < introductionScreens.length - 1 ? activeIndex : void 0
      },
      introductionScreens[activeIndex]
    ),
    /* @__PURE__ */ jsxs("div", { className: "adyen-kyc-introduction__nav", children: [
      /* @__PURE__ */ jsx(
        Button,
        {
          disabled: activeIndex === 0,
          onClick: () => {
            userEvents.addPageEvent("Clicked button", {
              ...pageEventDetails,
              actionType: "back",
              label: "back"
            });
            setActiveIndex((currentValue) => currentValue - 1);
          },
          variant: "secondary",
          children: t(($) => $["back"])
        }
      ),
      activeIndex + 1 === introductionScreens.length ? /* @__PURE__ */ jsx(
        Button,
        {
          onClick: () => {
            userEvents.addTaskEvent("Success", {
              actionType: "submit",
              label: "start"
            });
            onExitIntroduction();
          },
          children: t(($) => $["start"])
        }
      ) : /* @__PURE__ */ jsx(
        Button,
        {
          onClick: () => {
            userEvents.addPageEvent("Clicked button", {
              ...pageEventDetails,
              actionType: "next",
              label: "next"
            });
            setActiveIndex((currentValue) => currentValue + 1);
          },
          children: t(($) => $["continue"])
        }
      )
    ] })
  ] }) : null;
};
export {
  Introduction,
  IntroductionInner
};
