document.addEventListener("DOMContentLoaded", function () {
    const timerElement = document.getElementById("admilogu-lockout-timer");
    if (!timerElement) return;

    let totalSeconds = parseInt(timerElement.getAttribute("data-seconds"), 10);
    if (isNaN(totalSeconds) || totalSeconds <= 0) return;

    const updateTimerDisplay = (seconds) => {
        if (seconds <= 0) {
            timerElement.textContent = "0:00";
            // Optional: Reload after timer hits zero to let user try again
            setTimeout(() => {
                window.location.reload();
            }, 2000);
            return;
        }

        const minutes = Math.floor(seconds / 60);
        const secs = seconds % 60;
        timerElement.textContent = `${minutes}:${secs.toString().padStart(2, "0")}`;
    };

    const intervalId = setInterval(() => {
        totalSeconds--;
        updateTimerDisplay(totalSeconds);

        if (totalSeconds <= 0) {
            clearInterval(intervalId);
        }
    }, 1000);
});
