"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.useKeepInputVisible = void 0;
var react_1 = require("react");
var usePrevious_1 = require("../hooks/usePrevious");
var helpers_1 = require("./helpers");
var useKeepInputVisible = function (values, ref) {
    if (values === void 0) { values = []; }
    var prevValuesLength = (0, usePrevious_1.usePrevious)(values === null || values === void 0 ? void 0 : values.length);
    (0, react_1.useEffect)(function () {
        var timerId = setTimeout(function () {
            var _a;
            var parentElementWithScroll = (0, helpers_1.findNearestScrollableElement)(ref === null || ref === void 0 ? void 0 : ref.current);
            if (parentElementWithScroll &&
                (0, helpers_1.needToScroll)(values === null || values === void 0 ? void 0 : values.length, prevValuesLength, parentElementWithScroll, ref.current)) {
                (_a = ref.current) === null || _a === void 0 ? void 0 : _a.scrollIntoView(false);
            }
        }, 0);
        return function () {
            clearTimeout(timerId);
        };
        // eslint-disable-next-line react-hooks/exhaustive-deps
    }, [values === null || values === void 0 ? void 0 : values.length]);
};
exports.useKeepInputVisible = useKeepInputVisible;
