import { jsx as o } from "../../../../../preact@10.29.0/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useRef as G, useState as N, useMemo as H, useContext as J } from "../../../../../preact@10.29.0/node_modules/preact/hooks/dist/hooks.module.js";
import K from "classnames";
import { z as Q, u as U, W as i } from "./StoreProvider-CBB99upB.js";
import { L as X } from "./LoaderWrapper-BL7Hc_DC.js";
import { M as Y } from "./MaybeModal-7NGTfxO6.js";
import { P as Z } from "./ProgressBar-B7gTQncy.js";
import { F as $ } from "./dropinUtils-D44Paj5u.js";
import { C as oo } from "./Confirm-NubmSSR7.js";
import { S as eo } from "./Summary-C5uRwUKn.js";
import { createContext as no } from "../../../../../preact@10.29.0/node_modules/preact/dist/preact.module.js";
try {
  let n = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, s = new n.Error().stack;
  s && (n._sentryDebugIds = n._sentryDebugIds || {}, n._sentryDebugIds[s] = "8b1b752a-12c0-4345-9fff-f44cb1a28f1d", n._sentryDebugIdIdentifier = "sentry-dbid-8b1b752a-12c0-4345-9fff-f44cb1a28f1d");
} catch {
}
const S = no(null);
function Co({
  children: n,
  form: s
}) {
  const a = H(
    () => ({
      form: s
    }),
    [s]
  );
  return /* @__PURE__ */ o(S.Provider, { value: a, children: n });
}
const so = "adyen-kyc-form-flow", to = "adyen-kyc-form-flow-content", ro = "adyen-kyc-form-flow-footer", ao = "adyen-kyc-form-flow-footer-border", io = "adyen-kyc-form-flow-actions", lo = "adyen-kyc-form-flow-primary-actions", r = {
  formFlow: so,
  formFlowContent: to,
  formFlowFooter: ro,
  formFlowFooterBorder: ao,
  formFlowActions: io,
  formFlowPrimaryActions: lo
}, xo = ({
  asModal: n = !1,
  children: s,
  currentStep: a = 0,
  disableBackButton: y,
  disableNextButton: B,
  nextButtonLoading: M = !1,
  // used to separate button loading state from loading wrapper
  forms: b,
  activeForm: E,
  gotoFormByFormIndex: h,
  handleBackClick: g,
  handleCancelClick: p,
  handleNextClick: w,
  loadingStatus: F,
  summary: v,
  summaryComponent: C,
  totalSteps: l = 1
}) => {
  const c = G(null), x = Q(), { t } = U("common"), [P, d] = N(!1), [k, D] = N(!1), f = k || P || F === "loading", R = !!g, m = !!p, T = a === 0, A = a === l - 1, I = l < 2, _ = Math.floor(a / (l - 1) * 100), u = () => {
    c.current && c.current.scroll({
      top: 0,
      behavior: "smooth"
    });
  }, z = () => {
    D(!0), Promise.resolve(w()).then(() => {
      D(!1), u();
    });
  }, W = () => {
    u(), w();
  }, V = () => {
    u(), g?.();
  }, L = () => {
    m && d(!0);
  }, j = () => {
    x.addPageEvent("Closed modal", {
      actionType: "close",
      label: "cancel"
    }), d(!1);
  }, O = () => {
    x.addPageEvent("Clicked button", {
      actionType: "navigate",
      label: "leave"
    }), d(!1), p?.();
  }, q = K(r.formFlowFooter, {
    [r.formFlowFooterBorder]: I
  });
  return /* @__PURE__ */ o(
    Y,
    {
      inline: !n,
      onClose: L,
      size: "large",
      showCloseButton: m,
      children: [
        /* @__PURE__ */ o(
          "div",
          {
            ref: c,
            className: r.formFlow,
            "data-form-valid": E.isValid,
            "data-testid": "form-flow",
            children: [
              /* @__PURE__ */ o("div", { className: r.formFlowContent, children: /* @__PURE__ */ o(X, { status: F, formOpacityWhenLoading: 0, loaderSize: "large", children: /* @__PURE__ */ o($, { forms: b, setFormIndex: h, children: A ? C || (v !== void 0 ? /* @__PURE__ */ o(eo, { ...v, forms: b, gotoForm: h }) : s) : s }) }) }),
              /* @__PURE__ */ o("div", { className: q, children: [
                !I && /* @__PURE__ */ o(Z, { ariaLabel: t((e) => e.progress), progress: _ }),
                /* @__PURE__ */ o("div", { className: r.formFlowActions, children: [
                  T && m && /* @__PURE__ */ o(
                    i,
                    {
                      disabled: f || y,
                      onClick: L,
                      variant: "secondary",
                      children: t((e) => e.cancel)
                    }
                  ),
                  !T && R && /* @__PURE__ */ o(
                    i,
                    {
                      disabled: f || y,
                      icon: "chevron-left",
                      onClick: V,
                      variant: "secondary",
                      children: t((e) => e.back)
                    }
                  ),
                  /* @__PURE__ */ o("div", { className: r.formFlowPrimaryActions, children: A ? /* @__PURE__ */ o(i, { onClick: z, loading: k, children: t((e) => e.submit) }) : /* @__PURE__ */ o(
                    i,
                    {
                      onClick: W,
                      disabled: f || B,
                      loading: M,
                      children: t((e) => e.continue)
                    }
                  ) })
                ] })
              ] })
            ]
          }
        ),
        P && /* @__PURE__ */ o(
          oo,
          {
            confirmText: t((e) => e.leave),
            description: t((e) => e.unsavedChangesDescription),
            onCancel: j,
            onConfirm: O,
            title: t((e) => e.unsavedChanges)
          }
        )
      ]
    }
  );
};
function Po() {
  return J(S);
}
export {
  Co as F,
  xo as a,
  Po as u
};
