/**
 * levels-logic.js
 * Gère la logique des niveaux et le compte à rebours de sécurité.
 */
const LevelsLogic = {
    init: function() {
        console.log("Avision: Levels Logic Module Ready.");
    },

    formatTime: function(ms) {
        let seconds = Math.floor((ms / 1000) % 60);
        let minutes = Math.floor((ms / (1000 * 60)) % 60);
        let hours = Math.floor((ms / (1000 * 60 * 60)));
        
        return `${String(hours).padStart(2, '0')}h ${String(minutes).padStart(2, '0')}m ${String(seconds).padStart(2, '0')}s`;
    },

    startTimer: function(displayId, validationTimestamp) {
        const display = document.getElementById(displayId);
        if (!display) return;

        const seventyTwoHours = 72 * 60 * 60 * 1000;
        
        const update = () => {
            const now = new Date().getTime();
            const diff = (parseInt(validationTimestamp) + seventyTwoHours) - now;

            if (diff <= 0) {
                display.innerText = "00h 00m 00s";
                display.style.color = "#10b981";
                return;
            }

            display.innerText = this.formatTime(diff);
        };

        update();
        setInterval(update, 1000);
    }
};

export default LevelsLogic;
