import { jsx as _jsx } from "react/jsx-runtime";
//
// A component similar to DelayedTextInput from the @gravity-ui/components library
// https://github.com/gravity-ui/components/blob/c31e0b98ce866a8b42da93298c83f81dfb8459f7/src/components/DelayedTextInput/DelayedTextInput.tsx
//
import { forwardRef } from 'react';
import { TextArea } from '@gravity-ui/uikit';
import { useDelayedValue } from "../hooks/useDelayedValue.js";
function DelayedTextAreaComponent(props, ref) {
    const { value, onUpdate, delay, ...textAreaProps } = props;
    const { currentValue: textInputValue, delayedOnChange } = useDelayedValue(value, onUpdate, delay);
    // Without this proxy "native" input clear will synchronize value only after specified delay.
    const onChangeProxy = (event) => {
        textAreaProps.onChange?.(event);
        if (props.hasClear && event.type === 'click' && event.target.value === '') {
            onUpdate('');
        }
    };
    return (_jsx(TextArea, { ...textAreaProps, ref: ref, onChange: onChangeProxy, value: textInputValue, onUpdate: delayedOnChange }));
}
/***
 * Controlled textarea component. Property onUpdate is required in this component.
 */
export const DelayedTextArea = forwardRef(DelayedTextAreaComponent);
//# sourceMappingURL=DelayedTextArea.js.map
