"use strict";
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 __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputAutoComplete = void 0;
var react_1 = __importStar(require("react"));
var core_1 = require("@unform/core");
var Autocomplete_1 = require("../Autocomplete");
var InputAutoComplete_style_1 = __importDefault(require("./InputAutoComplete.style"));
exports.InputAutoComplete = function (_a) {
    var name = _a.name, fetch = _a.fetch, title = _a.title, prefix = _a.prefix, getValueText = _a.getValueText, getValue = _a.getValue, renderInput = _a.renderInput;
    var autocompleteRef = react_1.useRef();
    var _b = core_1.useField(name), registerField = _b.registerField, _c = _b.defaultValue, defaultValue = _c === void 0 ? '' : _c, error = _b.error, fieldName = _b.fieldName;
    react_1.useEffect(function () {
        registerField({
            name: fieldName,
            ref: autocompleteRef.current,
            path: 'value',
            setValue: function (ref, value) {
                ref = value;
            },
            getValue: function (ref) {
                return ref;
            },
        });
    }, [fieldName, registerField]);
    react_1.useEffect(function () {
        autocompleteRef.current.value = defaultValue;
    }, []);
    return (react_1.default.createElement(InputAutoComplete_style_1.default, { "data-cy": "autocomplete-" + name },
        react_1.default.createElement(Autocomplete_1.Autocomplete, { ref: autocompleteRef, defaultValue: defaultValue, name: name, title: title, fetch: fetch, error: !!error, prefix: prefix, renderInput: renderInput, select: function (i) {
                autocompleteRef.current.value = getValueText(i);
            } }),
        !!error && (react_1.default.createElement("div", { className: "error-input", "data-testid": "input-error" }, error))));
};
//# sourceMappingURL=InputAutoComplete.js.map