import { jsx as g } from "../../../../../preact@10.29.0/node_modules/preact/jsx-runtime/dist/jsxRuntime.module.js";
import { forwardRef as m } from "../../../../../preact@10.29.0/node_modules/preact/compat/dist/compat.module.js";
import { useState as I, useCallback as b, useLayoutEffect as h, useRef as v } from "../../../../../preact@10.29.0/node_modules/preact/hooks/dist/hooks.module.js";
import k from "classnames";
import { z as w } from "./StoreProvider-CBB99upB.js";
import { d as E } from "./debouncedInputEvent-Cv2S512Y.js";
try {
  let e = typeof window < "u" ? window : typeof global < "u" ? global : typeof globalThis < "u" ? globalThis : typeof self < "u" ? self : {}, a = new e.Error().stack;
  a && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[a] = "4f20d737-2dea-42ed-9fe4-584121c2c863", e._sentryDebugIdIdentifier = "sentry-dbid-4f20d737-2dea-42ed-9fe4-584121c2c863");
} catch {
}
const T = m((e, a) => {
  const i = w(), { enableTracking: s = !1, ...c } = e, { isInvalid: y, isValid: r, type: o = "text", disabled: d, name: u } = e, p = (t) => {
    s && E(i, { actionType: "input", field: u }), e.onInput?.(t);
  }, n = (t) => {
    s && i.addFieldEvent("Interacted with form field", {
      actionType: "blur",
      field: u
    }), e.onBlurHandler?.(t), e.trimOnBlur && (t.currentTarget.value = t.currentTarget.value.trim()), e.onBlur?.(t);
  }, l = (t) => {
    s && i.addFieldEvent("Interacted with form field", {
      actionType: "focus",
      field: u
    }), e.onFocusHandler?.(t);
  }, f = k("adyen-kyc-input", [`adyen-kyc-input--${o}`], e.className, {
    "adyen-kyc-input--invalid": y,
    "adyen-kyc-field--valid": r,
    "adyen-kyc-input--disabled": d
  });
  return /* @__PURE__ */ g(
    "input",
    {
      ...c,
      name: u,
      "aria-disabled": d,
      "aria-invalid": !r,
      "aria-required": c.required || c["aria-required"],
      className: f,
      onBlur: n,
      onFocus: l,
      onInput: p,
      ref: a,
      type: o
    }
  );
});
T.displayName = "InputBase";
const x = (e) => {
  const a = v();
  return e ?? a;
}, q = m(
  ({ onInput: e, onBlur: a, transformInput: i, transformMode: s, ...c }, y) => {
    const [r, o] = I(null), d = x(y), u = b(
      (n) => {
        const l = n.currentTarget;
        if (i && (!s || s === "input")) {
          o(l.selectionStart);
          const f = i(l.value), t = {
            ...n,
            target: { ...n.target, value: f }
          };
          e(t);
        } else
          e(n);
      },
      [i, s, e]
    ), p = b(
      (n) => {
        const l = n.currentTarget;
        if (i && s === "blur") {
          o(l.selectionStart);
          const f = i(l.value), t = {
            ...n,
            target: { ...n.target, value: f }
          };
          a?.(t);
        } else
          a?.(n);
      },
      [i, s, a]
    );
    return h(() => {
      r && d.current?.selectionStart !== r && d?.current?.setSelectionRange(r, r, "none");
    }, [r, d]), /* @__PURE__ */ g(
      T,
      {
        ...c,
        onInput: u,
        onBlur: p,
        ref: d,
        type: "text"
      }
    );
  }
);
export {
  q as I,
  T as a,
  x as u
};
