"use strict";
exports.__esModule = true;
exports.useScrollElements = void 0;
var react_1 = require("react");
function useScrollElements(items) {
    var refs = (0, react_1.useMemo)(function () {
        var refArray = [];
        for (var i = 0; i < items.length; i++) {
            refArray[i] = (0, react_1.createRef)();
        }
        return refArray;
    }, [items]);
    var scrollTo = function (index) {
        var _a;
        var currentRef = refs[index];
        var container = (_a = currentRef.current) === null || _a === void 0 ? void 0 : _a.parentElement;
        if (currentRef.current && container) {
            var defaultPadding = getComputedStyle(container).position !== 'relative' ? container.offsetLeft : 0;
            var scrollLeft = currentRef.current.offsetLeft - defaultPadding;
            if (index === 0) {
                scrollLeft = 0;
            }
            else if (index === refs.length - 1) {
                scrollLeft = container.scrollWidth;
            }
            container.scrollLeft = scrollLeft;
        }
    };
    return {
        refs: refs,
        scrollTo: scrollTo
    };
}
exports.useScrollElements = useScrollElements;
