;
{
  try {
    let e = "undefined" != typeof window ? window : "undefined" != typeof global ? global : "undefined" != typeof globalThis ? globalThis : "undefined" != typeof self ? self : {}, n = new e.Error().stack;
    n && (e._sentryDebugIds = e._sentryDebugIds || {}, e._sentryDebugIds[n] = "640ed60b-e92d-4e2b-97e7-e20154b2b172", e._sentryDebugIdIdentifier = "sentry-dbid-640ed60b-e92d-4e2b-97e7-e20154b2b172");
  } catch (e) {
  }
}
;
import { jsx } from "preact/jsx-runtime";
import { forwardRef } from "preact/compat";
import { useRef, useState, useCallback, useLayoutEffect } from "preact/hooks";
import cx from "classnames";
import { p as useAnalyticsContext } from "./StoreProvider-CqQrndhS.js";
import { d as debouncedInputEvent } from "./debouncedInputEvent-Cv2S512Y.js";
const InputBase = forwardRef((props, ref) => {
  const userEvents = useAnalyticsContext();
  const { enableTracking = false, ...passedProps } = props;
  const { isInvalid, isValid, type = "text", disabled, name } = props;
  const handleInput = (e) => {
    if (enableTracking) {
      debouncedInputEvent(userEvents, { actionType: "input", field: name });
    }
    props.onInput?.(e);
  };
  const handleBlur = (e) => {
    if (enableTracking) {
      userEvents.addFieldEvent("Interacted with form field", {
        actionType: "blur",
        field: name
      });
    }
    props.onBlurHandler?.(e);
    if (props.trimOnBlur) {
      e.currentTarget.value = e.currentTarget.value.trim();
    }
    props.onBlur?.(e);
  };
  const handleFocus = (e) => {
    if (enableTracking) {
      userEvents.addFieldEvent("Interacted with form field", {
        actionType: "focus",
        field: name
      });
    }
    props.onFocusHandler?.(e);
  };
  const inputClassNames = cx("adyen-kyc-input", [`adyen-kyc-input--${type}`], props.className, {
    "adyen-kyc-input--invalid": isInvalid,
    "adyen-kyc-field--valid": isValid,
    "adyen-kyc-input--disabled": disabled
  });
  return /* @__PURE__ */ jsx(
    "input",
    {
      ...passedProps,
      name,
      "aria-disabled": disabled,
      "aria-invalid": !isValid,
      "aria-required": passedProps.required || passedProps["aria-required"],
      className: inputClassNames,
      onBlur: handleBlur,
      onFocus: handleFocus,
      onInput: handleInput,
      ref,
      type
    }
  );
});
InputBase.displayName = "InputBase";
const useForwardedRef = (forwardedRef) => {
  const backupRef = useRef();
  return forwardedRef ?? backupRef;
};
const InputText = forwardRef(
  ({ onInput, onBlur, transformInput, transformMode, ...props }, ref) => {
    const [cursorPosition, setCursorPosition] = useState(null);
    const localRef = useForwardedRef(ref);
    const inputHandler = useCallback(
      (event) => {
        const inputEl = event.currentTarget;
        if (transformInput && (!transformMode || transformMode === "input")) {
          setCursorPosition(inputEl.selectionStart);
          const transformedInput = transformInput(inputEl.value);
          const eventWithTransformedValue = {
            ...event,
            target: { ...event.target, value: transformedInput }
          };
          onInput(eventWithTransformedValue);
        } else {
          onInput(event);
        }
      },
      [transformInput, transformMode, onInput]
    );
    const blurHandler = useCallback(
      (event) => {
        const inputEl = event.currentTarget;
        if (transformInput && transformMode === "blur") {
          setCursorPosition(inputEl.selectionStart);
          const transformedInput = transformInput(inputEl.value);
          const eventWithTransformedValue = {
            ...event,
            target: { ...event.target, value: transformedInput }
          };
          onBlur?.(eventWithTransformedValue);
        } else {
          onBlur?.(event);
        }
      },
      [transformInput, transformMode, onBlur]
    );
    useLayoutEffect(() => {
      if (cursorPosition && localRef.current?.selectionStart !== cursorPosition) {
        localRef?.current?.setSelectionRange(cursorPosition, cursorPosition, "none");
      }
    }, [cursorPosition, localRef]);
    return /* @__PURE__ */ jsx(
      InputBase,
      {
        ...props,
        onInput: inputHandler,
        onBlur: blurHandler,
        ref: localRef,
        type: "text"
      }
    );
  }
);
export {
  InputText as I,
  InputBase as a,
  useForwardedRef as u
};
