export class InfiniteScrollManager {
    constructor({ threshold = 300, loadMoreCallback, container = window, throttle = 200, debug = false, }) {
        this.handleScroll = () => {
            if (!this.isActive)
                return;
            const now = Date.now();
            if (now - this.lastCheck < this.throttleMs)
                return;
            this.lastCheck = now;
            const scrollPos = this.container instanceof Window
                ? window.scrollY + window.innerHeight
                : this.container.scrollTop +
                    this.container.clientHeight;
            const maxScroll = this.container instanceof Window
                ? document.body.offsetHeight
                : this.container.scrollHeight;
            if (scrollPos >= maxScroll - this.threshold) {
                if (this.debug)
                    console.log("Reached bottom, loading more content...");
                this.loadMoreCallback();
            }
        };
        this.threshold = threshold;
        this.loadMoreCallback = loadMoreCallback;
        this.container = container;
        this.debug = debug;
        this.isActive = true;
        this.lastCheck = 0;
        this.throttleMs = throttle;
        this.attach();
        if (this.debug)
            console.log("InfiniteScrollManager initialized");
    }
    attach() {
        this.container.addEventListener("scroll", this.handleScroll);
    }
    pause() {
        this.isActive = false;
        if (this.debug)
            console.log("InfiniteScrollManager paused");
    }
    resume() {
        this.isActive = true;
        if (this.debug)
            console.log("InfiniteScrollManager resumed");
    }
    destroy() {
        this.container.removeEventListener("scroll", this.handleScroll);
        if (this.debug)
            console.log("InfiniteScrollManager destroyed");
    }
}
//# sourceMappingURL=InfiniteScrollManager.js.map