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] = "38786a46-2b15-4d45-9262-4312b5dccbfd", e._sentryDebugIdIdentifier = "sentry-dbid-38786a46-2b15-4d45-9262-4312b5dccbfd");
} catch (e) {}
import { t as useAnalyticsContext } from "./useAnalyticsContext-DfTXpZbA.js";
import { t as debouncedInputEvent } from "./debouncedInputEvent-CUZBv60e.js";
import { forwardRef } from "preact/compat";
import { useCallback as useCallback$1, useLayoutEffect, useRef as useRef$1, useState as useState$1 } from "preact/hooks";
import cx from "classnames";
import { jsx } from "preact/jsx-runtime";
//#region src/components/ui/atoms/InputBase/InputBase.tsx
var 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";
//#endregion
//#region src/utils/useForwardRef.ts
var useForwardedRef = (forwardedRef) => {
	const backupRef = useRef$1();
	return forwardedRef ?? backupRef;
};
//#endregion
//#region src/components/ui/molecules/InputText/InputText.tsx
var InputText = forwardRef(({ onInput, onBlur, transformInput, transformMode, ...props }, ref) => {
	const [cursorPosition, setCursorPosition] = useState$1(null);
	const localRef = useForwardedRef(ref);
	const inputHandler = useCallback$1((event) => {
		const inputEl = event.currentTarget;
		if (transformInput && (!transformMode || transformMode === "input")) {
			setCursorPosition(inputEl.selectionStart);
			const transformedInput = transformInput(inputEl.value);
			onInput({
				...event,
				target: {
					...event.target,
					value: transformedInput
				}
			});
		} else onInput(event);
	}, [
		transformInput,
		transformMode,
		onInput
	]);
	const blurHandler = useCallback$1((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"
	});
});
//#endregion
export { useForwardedRef as n, InputBase as r, InputText as t };
