"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.DelayedTextArea = void 0;
const jsx_runtime_1 = require("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
//
const react_1 = require("react");
const uikit_1 = require("@gravity-ui/uikit");
const useDelayedValue_1 = require("../hooks/useDelayedValue.js");
function DelayedTextAreaComponent(props, ref) {
    const { value, onUpdate, delay, ...textAreaProps } = props;
    const { currentValue: textInputValue, delayedOnChange } = (0, useDelayedValue_1.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 ((0, jsx_runtime_1.jsx)(uikit_1.TextArea, { ...textAreaProps, ref: ref, onChange: onChangeProxy, value: textInputValue, onUpdate: delayedOnChange }));
}
/***
 * Controlled textarea component. Property onUpdate is required in this component.
 */
exports.DelayedTextArea = (0, react_1.forwardRef)(DelayedTextAreaComponent);
//# sourceMappingURL=DelayedTextArea.js.map
