import * as tslib_1 from "tslib";
import React, { useState } from 'react';
import classnames from 'classnames';
var defaultProps = {
    prefixCls: 'ty-textarea',
    disabled: false,
};
var Textarea = function (props) {
    var _a;
    var limit = props.limit, counter = props.counter, defaultValue = props.defaultValue, value = props.value, rows = props.rows, onChange = props.onChange, disabled = props.disabled, prefixCls = props.prefixCls, className = props.className, style = props.style, restProps = tslib_1.__rest(props, ["limit", "counter", "defaultValue", "value", "rows", "onChange", "disabled", "prefixCls", "className", "style"]);
    var cls = classnames(prefixCls, className, (_a = {},
        _a[prefixCls + "_disabled"] = disabled,
        _a));
    var _b = useState(0), count = _b[0], setCount = _b[1];
    var _inputOnChange = 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", tslib_1.__assign({ maxLength: limit, rows: rows, value: value, defaultValue: defaultValue, disabled: disabled, className: cls, style: style }, restProps, { onChange: _inputOnChange })),
            React.createElement("span", { className: prefixCls + "__counter" }, counter && (typeof counter === 'function') ? counter(count) : count + "/" + limit)));
    }
    else {
        return (React.createElement("textarea", tslib_1.__assign({ rows: rows, value: value, defaultValue: defaultValue, disabled: disabled, className: cls, style: style, onChange: _inputOnChange }, restProps)));
    }
};
Textarea.defaultProps = defaultProps;
export default Textarea;
//# sourceMappingURL=index.js.map