import { __assign, __rest } from "tslib";
import React, { useContext, useState } from 'react';
import classNames from 'classnames';
import { ConfigContext } from '../config-provider/config-context';
import { getPrefixCls } from '../_utils/general';
var Textarea = function (props) {
    var _a;
    var _b = props.disabled, disabled = _b === void 0 ? false : _b, customisedCls = props.prefixCls, limit = props.limit, counter = props.counter, defaultValue = props.defaultValue, value = props.value, rows = props.rows, onChange = props.onChange, className = props.className, style = props.style, otherProps = __rest(props, ["disabled", "prefixCls", "limit", "counter", "defaultValue", "value", "rows", "onChange", "className", "style"]);
    var configContext = useContext(ConfigContext);
    var prefixCls = getPrefixCls('textarea', configContext.prefixCls, customisedCls);
    var cls = classNames(prefixCls, className, (_a = {},
        _a[prefixCls + "_disabled"] = disabled,
        _a));
    var _c = useState(0), count = _c[0], setCount = _c[1];
    var textareaOnChange = function (e) {
        setCount(e.currentTarget.value.length);
        onChange && onChange(e.currentTarget.value, e);
    };
    if (limit || counter) {
        return (React.createElement("span", { className: prefixCls + "-container" },
            React.createElement("textarea", __assign({}, otherProps, { maxLength: limit, rows: rows, value: value, defaultValue: defaultValue, disabled: disabled, className: cls, style: style, onChange: textareaOnChange })),
            React.createElement("span", { className: prefixCls + "__counter" }, counter && typeof counter === 'function' ? counter(count) : count + "/" + limit)));
    }
    else {
        return (React.createElement("textarea", __assign({}, props, { rows: rows, value: value, defaultValue: defaultValue, disabled: disabled, className: cls, style: style, onChange: textareaOnChange })));
    }
};
Textarea.displayName = 'Textarea';
export default Textarea;
//# sourceMappingURL=index.js.map