"use strict";
var __assign = (this && this.__assign) || function () {
    __assign = Object.assign || function(t) {
        for (var s, i = 1, n = arguments.length; i < n; i++) {
            s = arguments[i];
            for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
                t[p] = s[p];
        }
        return t;
    };
    return __assign.apply(this, arguments);
};
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
    if (mod && mod.__esModule) return mod;
    var result = {};
    if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
var __rest = (this && this.__rest) || function (s, e) {
    var t = {};
    for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
        t[p] = s[p];
    if (s != null && typeof Object.getOwnPropertySymbols === "function")
        for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
            if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
                t[p[i]] = s[p[i]];
        }
    return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Textarea = exports.TextareaPure = void 0;
var react_1 = __importStar(require("react"));
var react_textarea_autosize_1 = __importDefault(require("react-textarea-autosize"));
var classnames_1 = __importDefault(require("classnames"));
var LoaderIcon_1 = require("../LoaderIcon");
var mask_utils_1 = require("../MaskText/mask.utils");
var styles_1 = require("../styles");
var Textarea_style_1 = __importDefault(require("./Textarea.style"));
var TextareaCore_1 = require("./TextareaCore");
exports.TextareaPure = react_1.default.forwardRef(function TextareaPure(props, inputRef) {
    var title = props.title, error = props.error, textRight = props.textRight, textCenter = props.textCenter, defaultValue = props.defaultValue, loading = props.loading, prefix = props.prefix, onEnter = props.onEnter, password = props.password, valueInput = props.value, suffix = props.suffix, withoutDotNumber = props.withoutDotNumber, as = props.as, rest = __rest(props, ["title", "error", "textRight", "textCenter", "defaultValue", "loading", "prefix", "onEnter", "password", "value", "suffix", "withoutDotNumber", "as"]);
    var ref = (0, react_1.useRef)();
    (0, react_1.useImperativeHandle)(inputRef, function () { return ref.current; }, []);
    var _a = (0, react_1.useState)(false), focus = _a[0], setFocus = _a[1];
    var value;
    if (valueInput != undefined) {
        value = (0, mask_utils_1.maskValue)(props.value, props.mask, props);
    }
    var _b = (0, react_1.useState)(true), hidePassword = _b[0], setHidePassword = _b[1];
    var className = ['input-border'];
    if (textRight)
        className.push('text-right');
    if ((rest === null || rest === void 0 ? void 0 : rest.type) == 'hidden')
        className.push('input-hidden');
    if (error)
        className.push('has-error');
    if (focus)
        className.push('focus');
    return (react_1.default.createElement(styles_1.FormStyle, { className: (0, classnames_1.default)('textarea-container', (rest === null || rest === void 0 ? void 0 : rest.disabled) && 'disabled') },
        react_1.default.createElement(Textarea_style_1.default, null,
            title && react_1.default.createElement("div", { className: "input-title ".concat(focus && 'focus') }, title),
            react_1.default.createElement("div", { className: className.join(' ') },
                prefix && react_1.default.createElement("div", { className: "prefix" }, prefix),
                react_1.default.createElement(react_textarea_autosize_1.default, __assign({ ref: ref, defaultValue: value ? '' : (0, mask_utils_1.maskValue)(defaultValue, props.mask, props), type: hidePassword && password ? 'password' : 'text', minRows: 4, maxRows: 4 }, rest, { value: value, onBlur: function (ev) {
                        if (rest.onBlur)
                            rest.onBlur(ev);
                        setFocus(false);
                    }, onFocus: function (ev) {
                        if (rest.onFocus)
                            rest.onFocus(ev);
                        setFocus(true);
                    }, onChange: function (evt) {
                        ref.current.value = evt.target.value;
                        if (rest.onChange)
                            rest.onChange(evt.target.value, evt);
                    }, onInput: function (evt) {
                        ref.current.value = evt.target.value;
                        if (rest.onInput)
                            rest.onInput(evt.target.value, evt);
                    }, className: "".concat(textCenter && ' text-center') })),
                loading && (react_1.default.createElement("div", { className: "suffix suffix-loading" },
                    react_1.default.createElement(LoaderIcon_1.LoaderIcon, { size: 18 }))),
                suffix && react_1.default.createElement("div", { className: "suffix" }, suffix)),
            error && (react_1.default.createElement("div", { className: "error-input", "data-testid": "input-error" }, error)))));
});
exports.Textarea = react_1.default.forwardRef(function Checkbox(props, inputRef) {
    var ref = (0, react_1.useRef)();
    (0, react_1.useImperativeHandle)(inputRef, function () { return ref.current; }, []);
    return react_1.default.createElement(TextareaCore_1.TextareaCore, __assign({}, props, { ref: ref, as: exports.TextareaPure }));
});
//# sourceMappingURL=Textarea.js.map