"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);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.useScrolledToEdge = void 0;
var react_1 = require("react");
var useIntersectionEffect_1 = require("./useIntersectionEffect");
var getLeftTarget = function (container) { return container.children[0]; };
var getRightTarget = function (container) { return container.children[container.children.length - 1]; };
exports.useScrolledToEdge = function (containerRef) {
    var _a = react_1.useState({ left: false, right: false }), onEdge = _a[0], setOnEdge = _a[1];
    useIntersectionEffect_1.useIntersectionEffect(containerRef, getLeftTarget, { threshold: .99 }, function (entries) {
        var lastEntry = entries[entries.length - 1];
        if (lastEntry.isIntersecting !== onEdge.left) {
            setOnEdge(function (prev) { return (__assign(__assign({}, prev), { left: lastEntry.isIntersecting })); });
        }
    });
    useIntersectionEffect_1.useIntersectionEffect(containerRef, getRightTarget, { threshold: .99 }, function (entries) {
        var lastEntry = entries[entries.length - 1];
        if (lastEntry.isIntersecting !== onEdge.right) {
            setOnEdge(function (prev) { return (__assign(__assign({}, prev), { right: lastEntry.isIntersecting })); });
        }
    });
    return __assign(__assign({}, onEdge), { both: onEdge.left && onEdge.right });
};
