export class ScrollElementManager {
    constructor(contentSelector, storageKey = "scrollpos", debug = false) {
        this.contentElement = document.querySelector(contentSelector);
        this.storageKey = storageKey;
        this.debug = debug;
        if (!this.contentElement) {
            if (this.debug)
                console.warn("ScrollElementManager: Element not found:", contentSelector);
            return;
        }
        this.initialize();
    }
    initialize() {
        var _a;
        window.addEventListener("load", this.loadScrollPosition.bind(this));
        (_a = this.contentElement) === null || _a === void 0 ? void 0 : _a.addEventListener("scroll", this.updateScrollPosition.bind(this));
        if (this.debug)
            console.log("ScrollElementManager initialized.");
    }
    loadScrollPosition() {
        try {
            const scrollpos = sessionStorage.getItem(this.storageKey);
            if (scrollpos !== null && this.contentElement) {
                this.contentElement.scrollTop = parseInt(scrollpos, 10);
                sessionStorage.removeItem(this.storageKey);
                if (this.debug)
                    console.log("Scroll position restored:", scrollpos);
            }
        }
        catch (err) {
            if (this.debug)
                console.error("ScrollElementManager error loading scroll position:", err);
        }
    }
    updateScrollPosition() {
        try {
            if (this.contentElement) {
                sessionStorage.setItem(this.storageKey, this.contentElement.scrollTop.toString());
                if (this.debug)
                    console.log("Scroll position saved:", this.contentElement.scrollTop);
            }
        }
        catch (err) {
            if (this.debug)
                console.error("ScrollElementManager error saving scroll position:", err);
        }
    }
}
//# sourceMappingURL=ScrollElementManager.js.map