"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.usePaginationLoadable = void 0;
const react_1 = __importDefault(require("react"));
const _1 = require(".");
const utility_1 = require("../utility");
const usePaginationLoadable = (input) => {
    const analyticsHook = (0, _1.useAnalytics)();
    const { filterStack } = (0, _1.useFilters)();
    const hasMore = input.resultStats.displayedResults !== input.resultStats.numberOfResults;
    const handleLoadMore = react_1.default.useCallback(() => {
        utility_1.debug.log("usePaginationLoadable", "handleLoadMore");
        if (!hasMore) {
            return;
        }
        input.loadMore();
        analyticsHook.track({
            eventName: "paginationChange",
            payload: {
                page: Math.ceil(input.resultStats.displayedResults / ((filterStack === null || filterStack === void 0 ? void 0 : filterStack.pageSize) || 20)) + 1,
                source: window.location.pathname.includes("/search")
                    ? "search"
                    : "collection",
            },
        });
    }, [input.loadMore, analyticsHook.track, input.resultStats, filterStack]);
    return react_1.default.useMemo(() => ({
        loading: input.loading,
        hasMore,
        handleLoadMore,
        resultStats: input.resultStats,
    }), [input.loading, hasMore, handleLoadMore, input.resultStats]);
};
exports.usePaginationLoadable = usePaginationLoadable;
//# sourceMappingURL=usePaginationLoadable.js.map