"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;
    Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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.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 = void 0;
var react_1 = __importStar(require("react"));
var react_textarea_autosize_1 = __importDefault(require("react-textarea-autosize"));
var core_1 = require("@unform/core");
var Textarea_style_1 = __importDefault(require("./Textarea.style"));
exports.Textarea = function (_a) {
    var name = _a.name, title = _a.title, disabled = _a.disabled, theme = _a.theme, rest = __rest(_a, ["name", "title", "disabled", "theme"]);
    var inputRef = react_1.useRef(null);
    var _b = core_1.useField(name), registerField = _b.registerField, _c = _b.defaultValue, defaultValue = _c === void 0 ? '' : _c, error = _b.error, fieldName = _b.fieldName;
    var _d = react_1.useState(false), focus = _d[0], setFocus = _d[1];
    react_1.useEffect(function () {
        registerField({
            name: fieldName,
            ref: inputRef.current,
            path: 'value',
            setValue: function (ref, value) {
                inputRef.current.value = value || '';
            },
            getValue: function (ref) {
                return ref.value;
            },
        });
    }, [fieldName, registerField]);
    return (react_1.default.createElement(Textarea_style_1.default, { themeInput: theme, disabled: disabled },
        react_1.default.createElement("div", { className: "input-title " + (focus && 'focus') }, title),
        react_1.default.createElement(react_textarea_autosize_1.default, __assign({ ref: inputRef, defaultValue: defaultValue, onBlur: function (ev) {
                if (rest.onBlur)
                    rest.onBlur(ev);
                setFocus(false);
            }, onFocus: function (ev) {
                if (rest.onFocus)
                    rest.onFocus(ev);
                setFocus(true);
            }, disabled: disabled, className: (error && 'has-error') + " " + (focus && 'focus') + " ", "data-testid": "input-textarea" }, rest)),
        error && (react_1.default.createElement("div", { "data-cy": "input-error." + '', className: "error-input", "data-testid": "input-error" }, error))));
};
//# sourceMappingURL=Textarea.js.map