import { jsx as e } from "../../../../../preact@10.29.0/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { useCallback as C, useContext as O } from "../../../../../preact@10.29.0/node_modules/preact/hooks/dist/hooks.module.js";
import { u as _, b9 as I, G as R, aS as M, W as j } from "./StoreProvider-CBB99upB.js";
import { createContext as x, Fragment as k } from "../../../../../preact@10.29.0/node_modules/preact/dist/preact.module.js";
try {
  let r = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, a = new r.Error().stack;
  a && (r._sentryDebugIds = r._sentryDebugIds || {}, r._sentryDebugIds[a] = "3a025c01-b327-4db7-bb88-c8dce86f311e", r._sentryDebugIdIdentifier = "sentry-dbid-3a025c01-b327-4db7-bb88-c8dce86f311e");
} catch {
}
const E = "adyen-kyc-error-panel", N = {
  errorPanel: E
}, T = x(null);
function $() {
  return O(T);
}
const m = ({ fieldName: r, label: a }) => {
  const { goToFormByFieldName: n, getFieldAction: o } = $();
  return /* @__PURE__ */ e(j, { onClick: () => {
    const t = o(r);
    t ? t() : n(r);
  }, variant: "link", children: a });
};
function L({
  validationErrors: r,
  formUtils: a
}) {
  const { t: n } = _("ui"), o = Object.keys(r || {}), d = C(
    () => n((t) => t.fieldHasUnsupportedFormats, {
      fieldName: a.getLabel(o[0])
    }),
    [n, a, o]
  );
  return /* @__PURE__ */ e(R, { title: n((t) => t.informationCouldNotBeSubmitted), variant: "error", children: o?.length === 1 ? /* @__PURE__ */ e("div", { "data-testid": "validation-error--case-1", children: [
    d(),
    " ",
    /* @__PURE__ */ e(
      m,
      {
        fieldName: o[0],
        label: n((t) => t.updateTheInformation)
      }
    ),
    " ",
    n((t) => t.andResubmit)
  ] }) : /* @__PURE__ */ e("div", { "data-testid": "validation-error--case-2", children: [
    n((t) => t.someFieldsHaveUnsupportedFormatedUpdateInfoAndResubmit),
    /* @__PURE__ */ e("ul", { children: o.map((t) => /* @__PURE__ */ e(
      "li",
      {
        className: "adyen-kyc-error-panel__validation-error",
        "data-testid": "adyen-kyc-error-panel__validation-error",
        children: /* @__PURE__ */ e(m, { fieldName: t, label: a.getLabel(t) })
      },
      t
    )) })
  ] }) });
}
function D({
  verificationErrors: r,
  formUtils: a
}) {
  const { t: n } = _("common"), o = (i) => n((s) => s[`errorMessage_${i}`]), d = (i, s) => {
    const u = s ? Object.keys(s) : [];
    if (i?.length === 1 && u.length === 1) {
      const l = u[0], c = n(
        (f) => f[`remediationMessage_${s[l]?.remediation.code}`]
      );
      return /* @__PURE__ */ e(m, { fieldName: l, label: c });
    }
    if (i?.length === 1)
      return n((l) => l[`remediationMessage_${i[0].code}`]);
    let h;
    if (u.length > 0)
      if (u.length > 1) {
        const l = u.map((c) => /* @__PURE__ */ e(
          m,
          {
            fieldName: c,
            label: n(
              (f) => f[`remediationMessage_${s[c]?.remediation.code}`]
            )
          },
          c
        ));
        h = /* @__PURE__ */ e(k, { children: [
          a.getLabel("uploadTheFollowingDocuments"),
          /* @__PURE__ */ e("ul", { children: l.map((c, f) => /* @__PURE__ */ e("li", { children: c }, f)) })
        ] });
      } else {
        const l = u[0], c = ` ${n(
          (f) => f[`remediationMessage_${s[l]?.remediation.code}`]
        )?.toLowerCase()}`;
        h = /* @__PURE__ */ e(m, { fieldName: l, label: c });
      }
    return /* @__PURE__ */ e(k, { children: [
      n((l) => l.reviewTheInformationBelowAndCorrectMistakesOr),
      " ",
      h,
      " ",
      n((l) => l.thenResubmit)
    ] });
  };
  let t, p;
  const F = M(r);
  F.length === 1 && (p = F[0]);
  const y = Object.values(r).reduce(
    (i, s) => ({
      ...i,
      ...s
    }),
    {}
  ), g = Object.keys(y), v = Object.values(y).flat().reduce((i, s) => {
    const u = I(s), h = s.fields?.[0];
    return u && h && (i[h] = {
      formName: s?.forms[0],
      remediation: s
    }), i;
  }, {}), b = Object.values(y).flat();
  g.length === 1 ? t = /* @__PURE__ */ e(
    "div",
    {
      "data-testid": `verification-error--case-${b.length === 1 ? "1" : "2-1"}`,
      children: [
        /* @__PURE__ */ e("span", { children: `${o(g[0])} ` }),
        /* @__PURE__ */ e("span", { children: d(b, v) })
      ]
    }
  ) : g.length === 2 ? t = /* @__PURE__ */ e("div", { "data-testid": "verification-error--case-2-2", children: [
    n((i) => i.weFoundTheFollowingIssues),
    /* @__PURE__ */ e("ul", { children: g.map((i) => /* @__PURE__ */ e("li", { children: /* @__PURE__ */ e("span", { children: o(i) }) }, i)) }),
    /* @__PURE__ */ e("span", { children: d(b, v) })
  ] }) : t = /* @__PURE__ */ e("div", { "data-testid": "verification-error--case-2-3", children: d(b, v) });
  const w = p ? o(p) : n((i) => i.correctErrorsResubmit);
  return /* @__PURE__ */ e(R, { title: w, variant: "error", children: t });
}
function H({
  id: r = "ariaErrorField",
  verificationErrors: a,
  validationErrors: n,
  formUtils: o
}) {
  const d = a && Object.keys(a).length > 0, t = n && Object.keys(n).length > 0;
  return !d && !t ? null : /* @__PURE__ */ e("div", { className: N.errorPanel, id: r, "aria-live": "polite", children: [
    d && !t && /* @__PURE__ */ e(D, { formUtils: o, verificationErrors: a }),
    t && /* @__PURE__ */ e(L, { formUtils: o, validationErrors: n })
  ] });
}
export {
  H as E,
  T as F,
  $ as u
};
