"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.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
    __setModuleDefault(result, mod);
    return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextareaCoreWithoutUnform = exports.TextareaCoreWithUnform = exports.TextareaCore = void 0;
var react_1 = __importStar(require("react"));
var core_1 = require("@unform/core");
exports.TextareaCore = react_1.default.forwardRef(function TextareaCore(props, inputRef) {
    var ref = react_1.useRef();
    react_1.useImperativeHandle(inputRef, function () { return ref.current; }, []);
    if (props.name) {
        return react_1.default.createElement(exports.TextareaCoreWithUnform, __assign({}, props, { ref: ref }));
    }
    return react_1.default.createElement(exports.TextareaCoreWithoutUnform, __assign({}, props, { ref: ref }));
});
exports.TextareaCoreWithUnform = react_1.default.forwardRef(function TextareaCoreWithUnform(props, inputRef) {
    var ref = react_1.useRef();
    react_1.useImperativeHandle(inputRef, function () { return ref.current; }, []);
    var _a = core_1.useField(props.name), fieldName = _a.fieldName, registerField = _a.registerField, _b = _a.defaultValue, defaultValue = _b === void 0 ? null : _b, error = _a.error, clearError = _a.clearError;
    react_1.useEffect(function () {
        registerField({
            name: fieldName,
            ref: ref,
            path: 'current',
            clearValue: function (_ref) {
                var _a, _b;
                ref.current.value = '';
                if ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.clear)
                    (_b = ref.current) === null || _b === void 0 ? void 0 : _b.clear();
            },
            setValue: function (_ref, value) {
                ref.current.value = value;
            },
            getValue: function (_ref) {
                return ref.current.value;
            },
        });
    }, [fieldName, registerField]);
    var onInput = react_1.useCallback(function onSelectItem(text) {
        clearError();
        if (props.onInput)
            props.onInput(text);
    }, []);
    return (react_1.default.createElement(exports.TextareaCoreWithoutUnform, __assign({}, props, { ref: ref, onInput: onInput, value: null, error: error, defaultValue: defaultValue })));
});
exports.TextareaCoreWithoutUnform = react_1.default.forwardRef(function TextareaCoreWithoutUnform(props, inputRef) {
    var ref = react_1.useRef(null);
    react_1.useImperativeHandle(inputRef, function () { return ref.current; }, []);
    var PureComponent = react_1.useMemo(function () { return props.as || 'input'; }, [props.as]);
    return react_1.default.createElement(PureComponent, __assign({}, props, { ref: ref }));
});
//# sourceMappingURL=TextareaCore.js.map