import { jsx as n } from "../../../../../preact@10.29.0/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import N from "classnames";
import { useEffect as D } from "../../../../../preact@10.29.0/node_modules/preact/hooks/dist/hooks.module.js";
import { u as R, z as A, B as $, ac as j } from "./StoreProvider-CBB99upB.js";
import { a as H } from "./useId-BZ0PA7jP.js";
try {
  let a = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, t = new a.Error().stack;
  t && (a._sentryDebugIds = a._sentryDebugIds || {}, a._sentryDebugIds[t] = "a1942dde-6355-4080-a792-8d8c1871241a", a._sentryDebugIdIdentifier = "sentry-dbid-a1942dde-6355-4080-a792-8d8c1871241a");
} catch {
}
const g = "-ariaError", q = ({
  children: a,
  className: t,
  name: o,
  disabled: y,
  el: s,
  dataTestId: e
}) => s === "fieldset" ? /* @__PURE__ */ n("fieldset", { name: o, disabled: y, className: t, "data-testid": e, children: a }) : /* @__PURE__ */ n("div", { className: t, "data-testid": e, children: a }), U = ({
  className: a,
  classNameModifiers: t = [],
  children: o,
  disabled: y,
  optional: s,
  errorMessage: e,
  formatGuidance: r,
  helper: c,
  helperPosition: b = "above",
  isValid: m,
  label: p,
  name: f,
  showErrorIconBottom: k = !1,
  showErrorIcon: T = !0,
  el: u = "div",
  dataTestId: w,
  onBlur: v,
  onFieldBlur: _,
  onFocus: h
}) => {
  const l = H("field"), { t: x } = R("common"), I = A(), E = u === "fieldset" ? "legend" : "label";
  D(() => {
    if (!e) return;
    const i = typeof e == "string" && e || typeof e == "object" && e.key || "invalid";
    I.addFieldEvent("Encountered error", {
      actionType: "input",
      field: f,
      returnType: "validation",
      returnValue: i
    });
  }, [f, e, I]);
  const d = {
    label: `${l}-label`,
    helper: `${l}-helper`,
    error: `${l}${g}`,
    guidanceText: `${l}-guidanceText`
  }, F = `${e ? d.error : ""} ${c ? d.helper : ""} ${r ? d.guidanceText : ""}`.trim();
  return /* @__PURE__ */ n(
    q,
    {
      className: N(
        "adyen-kyc-field",
        a,
        t.map((i) => `adyen-kyc-field--${i}`),
        {
          "adyen-kyc-field--error": !!e,
          "adyen-kyc-field--valid": m,
          "adyen-kyc-field--disabled": y
        }
      ),
      name: f,
      disabled: y,
      el: u,
      dataTestId: w,
      children: [
        p && /* @__PURE__ */ n(
          E,
          {
            id: d.label,
            htmlFor: u === "fieldset" ? void 0 : l,
            className: N("adyen-kyc-label__text", {
              "adyen-kyc-label__text--error": !!e
            }),
            children: [
              p,
              s && /* @__PURE__ */ n("span", { className: "adyen-kyc-optional-label", children: [
                " ",
                x((i) => i.optional)
              ] })
            ]
          }
        ),
        c && b === "above" && /* @__PURE__ */ n("span", { id: d.helper, className: "adyen-kyc-helper-text adyen-kyc-helper-text__above", children: c }),
        /* @__PURE__ */ n("div", { className: "adyen-kyc-input-wrapper", children: [
          o({
            id: l,
            "aria-labelledby": d.label,
            "aria-describedby": F,
            isInvalid: !!e,
            isValid: !!m,
            onBlurHandler: (i) => {
              typeof v == "function" && v(i), typeof _ == "function" && _(i);
            },
            onFocusHandler: (i) => {
              typeof h == "function" && h(i);
            }
          }),
          c && b === "below" && /* @__PURE__ */ n(
            "span",
            {
              id: d.helper,
              className: "adyen-kyc-helper-text adyen-kyc-helper-text__below",
              children: c
            }
          ),
          !!e && !k && T && /* @__PURE__ */ n("span", { className: "adyen-kyc-input__inline-validation adyen-kyc-input__inline-validation--invalid", children: /* @__PURE__ */ n($, { name: "field-error" }) })
        ] }),
        /* @__PURE__ */ n("div", { "aria-live": "polite", "aria-atomic": !0, className: "adyen-kyc-error-text", children: [
          /* @__PURE__ */ n("span", { className: "adyen-kyc-u-screen-reader-only", children: `${p}:` }),
          !!e && typeof e != "boolean" && /* @__PURE__ */ n("span", { id: d.error, children: [
            j(x, e),
            k && /* @__PURE__ */ n("span", { className: "adyen-kyc-input__inline-validation adyen-kyc-input__inline-validation--invalid-bottom", children: /* @__PURE__ */ n($, { name: "field-error" }) })
          ] })
        ] }),
        !e && r && /* @__PURE__ */ n("span", { id: d.guidanceText, "aria-live": "polite", className: "adyen-kyc-guidance-text", children: r })
      ]
    }
  );
};
export {
  U as F
};
