"use strict";
class NewsBadge {
    static create() {
        return new NewsBadge();
    }
    constructor() {
        var _a;
        this.container = document.getElementById('news-list');
        this.serviceName = (_a = this.container) === null || _a === void 0 ? void 0 : _a.getAttribute('data-service');
        this.localStorageName = `${this.serviceName}_news_last`;
        if (this.container == null) {
            return;
        }
        // @ts-ignore
        if (this.container.NewsBadge) {
            return;
        }
        this.render();
        this.handleDropdownHide();
        // @ts-ignore
        this.container.NewsBadge = this;
    }
    getCurrentDate() {
        return new Date(this.container.getAttribute('data-last-news'));
    }
    toggleBadge(show) {
        var _a;
        (_a = this.container.querySelector('.badge')) === null || _a === void 0 ? void 0 : _a.classList.toggle('d-none', !show);
    }
    saveLastDate() {
        localStorage.setItem(this.localStorageName, this.getCurrentDate().toISOString());
    }
    handleDropdownHide() {
        this.container.addEventListener('show.bs.dropdown', () => {
            this.saveLastDate();
            this.toggleBadge(false);
        });
    }
    render() {
        const storageDateText = localStorage.getItem(this.localStorageName);
        if (storageDateText != null) {
            const storageDate = new Date(storageDateText);
            const actualDate = this.getCurrentDate();
            if (actualDate.getTime() > storageDate.getTime()) {
                this.toggleBadge(true);
            }
        }
        else {
            this.saveLastDate();
        }
    }
}
document.addEventListener('DOMContentLoaded', () => {
    NewsBadge.create();
});
