;
{
  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] = "1de30dca-8c1f-4ec3-88e3-df6d6d42b907", e._sentryDebugIdIdentifier = "sentry-dbid-1de30dca-8c1f-4ec3-88e3-df6d6d42b907");
  } catch (e) {
  }
}
;
import { jsxs, jsx } from "preact/jsx-runtime";
import { useState } from "preact/hooks";
import { u as useTranslation, p as useAnalyticsContext, v as useExperimentsContext, V as Button } from "./StoreProvider-CqQrndhS.js";
import { L as LoaderWrapper } from "./LoaderWrapper-Dr1uK-LS.js";
import { M as MaybeModal } from "./MaybeModal-C21jAgAp.js";
import { a as ModalContent, b as ModalHeader, c as ModalFooter } from "./Modal-1lLoobr9.js";
import { S as Spacer } from "./Spacer-BK3jDget.js";
import { S as StepProgressIndicator } from "./StepProgressIndicator-C2DPnOQi.js";
import { F as FormRouterContextProvider } from "./dropinUtils-G5Ua27s3.js";
import { F as FormNavigation } from "./FormNavigation-BJzGPCsX.js";
import { s as summaryStep, S as Summary } from "./Summary-6z7-keBb.js";
const FormWrapper = ({
  asModal = false,
  summary,
  taskName,
  children,
  handleNextClick,
  handleBackClick,
  handleCloseClick,
  handleHomeClick,
  loadingStatus,
  gotoFormByFormIndex,
  forms,
  activeForm,
  validateForm,
  hideSidebar,
  hideFooter,
  canSubmit,
  onSubmit,
  problems,
  steps,
  showBackButton,
  hideNextButton,
  hideHomeButton
}) => {
  const { t } = useTranslation("common");
  const userEvents = useAnalyticsContext();
  const { data: summaryData, omitted, labels } = summary || {};
  const [finishLaterLoading, setFinishLaterLoading] = useState(false);
  const showLegalCaption = ["solePropDetails", "companyDetails", "businessDetails"].includes(
    taskName
  );
  const { isExperimentEnabled } = useExperimentsContext();
  const showExtraTaxExemptionReasons = isExperimentEnabled("ShowExtraTaxExemptionReasons");
  const showTaxExemptedLegalCaption = showExtraTaxExemptionReasons && summaryData?.companyRegistrationDetails?.vatAbsenceReason && ["companyDetails", "businessDetails"].includes(taskName);
  const summaryContent = /* @__PURE__ */ jsx("div", { className: "adyen-kyc-form-wrapper", children: /* @__PURE__ */ jsx(
    Summary,
    {
      data: summaryData,
      omitted,
      forms,
      gotoForm: gotoFormByFormIndex,
      labels,
      problems,
      showLegalCaption,
      showTaxExemptedLegalCaption
    }
  ) });
  const onHomeClick = () => {
    setFinishLaterLoading(true);
    userEvents.addPageEvent("Clicked button", {
      actionType: "save",
      label: "finishLater"
    });
    if (canSubmit) {
      onSubmit().then(() => {
        setFinishLaterLoading(false);
      });
    } else {
      handleHomeClick?.();
      setFinishLaterLoading(false);
    }
  };
  const isFirstStep = steps.current === 0;
  const isFinalStep = steps.current === steps.total - 1;
  return /* @__PURE__ */ jsxs(MaybeModal, { inline: !asModal, onClose: handleCloseClick, size: "large", children: [
    /* @__PURE__ */ jsxs(ModalContent, { children: [
      /* @__PURE__ */ jsx(ModalHeader, {}),
      /* @__PURE__ */ jsx(LoaderWrapper, { status: loadingStatus, formOpacityWhenLoading: 0.3, loaderSize: "large", children: /* @__PURE__ */ jsxs("div", { className: !hideSidebar ? "adyen-kyc-form-with-sidebar" : "", children: [
        !asModal && !hideSidebar && /* @__PURE__ */ jsx("div", { className: "adyen-kyc-dropin__sidebar-wrapper", children: /* @__PURE__ */ jsx(
          FormNavigation,
          {
            forms,
            activeForm,
            gotoForm: gotoFormByFormIndex,
            validateForm,
            taskName,
            verificationErrors: problems?.verificationErrors
          }
        ) }),
        /* @__PURE__ */ jsxs(FormRouterContextProvider, { setFormIndex: gotoFormByFormIndex, forms, children: [
          children,
          activeForm.formId === summaryStep.formId && summary && summaryContent
        ] })
      ] }) })
    ] }),
    !hideFooter && /* @__PURE__ */ jsxs(ModalFooter, { children: [
      /* @__PURE__ */ jsx("div", { style: { width: "30%", display: asModal ? "unset" : "none" }, children: /* @__PURE__ */ jsx(
        StepProgressIndicator,
        {
          activeStepIndex: steps.current ?? 0,
          stepsCount: steps.total,
          fillBefore: true,
          thick: true
        }
      ) }),
      (!isFirstStep || showBackButton) && handleBackClick && /* @__PURE__ */ jsx(Button, { icon: "chevron-left", variant: "secondary", onClick: handleBackClick, children: t(($) => $["back"]) }),
      /* @__PURE__ */ jsx(Spacer, {}),
      !isFirstStep && !isFinalStep && !hideHomeButton && /* @__PURE__ */ jsx(
        Button,
        {
          variant: "secondary",
          icon: "save",
          onClick: onHomeClick,
          loading: finishLaterLoading,
          children: t(($) => $["finishLater"])
        }
      ),
      !isFinalStep && !hideNextButton && /* @__PURE__ */ jsx(Button, { onClick: handleNextClick, children: t(($) => $["continue"]) }),
      isFinalStep && /* @__PURE__ */ jsx(Button, { onClick: handleNextClick, children: t(($) => $["submit"]) })
    ] })
  ] });
};
export {
  FormWrapper as F
};
