import { jsx as r } from "../../../../../preact@10.29.0/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import _ from "classnames";
import { u as h, z as k, O as g, B as u } from "./StoreProvider-CBB99upB.js";
import { t as p } from "./trackNavigation-db_h46BT.js";
import { K as v } from "./Modal-BMdWqd0Y.js";
import { Fragment as F } from "../../../../../preact@10.29.0/node_modules/preact/dist/preact.module.js";
try {
  let e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, o = new e.Error().stack;
  o && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[o] = "bd24104e-37f0-4dcb-86ec-3418a722a40a", e._sentryDebugIdIdentifier = "sentry-dbid-bd24104e-37f0-4dcb-86ec-3418a722a40a");
} catch {
}
const V = ({
  form: e,
  isActive: o,
  onClick: i,
  hasVerificationErrors: s
}) => {
  const { t } = h("common"), d = e.hasServerValidationErrors || s, c = (n) => {
    i && (n.key === v.enter || n.key === v.space) && (n.preventDefault(), i());
  };
  return /* @__PURE__ */ r(
    "li",
    {
      "aria-label": t((n) => n[e.formName]),
      "aria-current": o,
      className: _("adyen-kyc-form-navigation__item", {
        "adyen-kyc-form-navigation__item--active": o,
        "adyen-kyc-form-navigation__item--valid": e.isValid,
        "adyen-kyc-form-navigation__item--isnav": !!i
      }),
      children: /* @__PURE__ */ r(
        "button",
        {
          type: "button",
          onClick: i,
          onKeyDown: i ? c : void 0,
          tabIndex: i ? 0 : void 0,
          children: [
            t((n) => n[e.formName]),
            e.hasServerValidationErrors && /* @__PURE__ */ r("span", { className: "adyen-kyc-form-navigation__item-icon adyen-kyc-form-navigation__item-icon--error", children: [
              /* @__PURE__ */ r(u, { name: "warning" }),
              /* @__PURE__ */ r("span", { className: "adyen-kyc-u-screen-reader-only", children: t((n) => n.formStepInvalid) })
            ] }),
            e.isValid && !d && /* @__PURE__ */ r("span", { className: "adyen-kyc-form-navigation__item-icon adyen-kyc-form-navigation__item-icon--success", children: [
              /* @__PURE__ */ r(u, { name: "checkmark-small" }),
              /* @__PURE__ */ r("span", { className: "adyen-kyc-u-screen-reader-only", children: t((n) => n.formStepCompleted) })
            ] })
          ]
        }
      )
    },
    e.formId
  );
};
function Y({
  forms: e,
  activeForm: o,
  gotoForm: i,
  validateForm: s,
  className: t,
  taskName: d,
  verificationErrors: c
}) {
  const { t: n } = h("common"), y = k(), f = n((a) => a[d]), l = (a) => e.findIndex((m) => m.formId === a.formId), I = (a) => () => {
    a.formId !== o.formId && (i(l(a)), p({
      userEvents: y,
      actionType: "navigate",
      toForm: a.formName,
      label: a.formName,
      returnValue: "success"
    }));
  }, b = (a, m) => e.slice(0, l(a)).every((N) => N.isValid) || !s ? I(a) : m.isValid ? void 0 : () => {
    p({
      userEvents: y,
      actionType: "navigate",
      toForm: a.formName,
      label: a.formName,
      returnValue: "validation error"
    }), s();
  };
  return /* @__PURE__ */ r("div", { className: _("adyen-kyc-form-navigation", t), children: [
    /* @__PURE__ */ r(
      g,
      {
        el: "h3",
        variant: "body",
        color: "secondary",
        className: "adyen-kyc-form-navigation__header",
        children: f
      }
    ),
    e && /* @__PURE__ */ r(F, { children: [
      /* @__PURE__ */ r(
        g,
        {
          color: "tertiary",
          variant: "caption-stronger",
          className: "adyen-kyc-form-navigation__step-count",
          children: n((a) => a["stepsX/YofForm"], {
            activeFormIndex: l(o) + 1,
            totalForms: e.length,
            taskNameTranslated: f
          })
        }
      ),
      /* @__PURE__ */ r("ul", { className: "adyen-kyc-form-navigation__items", children: e.map((a) => /* @__PURE__ */ r(
        V,
        {
          form: a,
          isActive: a.formId === o.formId,
          onClick: b(a, o),
          hasVerificationErrors: !!(c?.[a.formId] ?? !1)
        },
        a.formId
      )) })
    ] })
  ] });
}
export {
  Y as F
};
