/**
 * Template Name: Inspinia - Admin & Dashboard Template
 * By (Author): WebAppLayers
 * Module/App (File Name): Coming Soon
 */

class Countdown {
    initCountDown() {
        const daysEl = document.getElementById("days")
        const hoursEl = document.getElementById("hours")
        const minutesEl = document.getElementById("minutes")
        const secondsEl = document.getElementById("seconds")

        if (daysEl && hoursEl && minutesEl && secondsEl) {
            // The data/time we want to countdown to
            const eventCountDown = new Date("Sep 27, 2028 12:00:01").getTime()

            // Run myfunc every second
            const count = setInterval(function () {
                const now = new Date().getTime()
                const timeleft = eventCountDown - now

                // Calculating the days, hours, minutes and seconds left
                const days = Math.floor(timeleft / (1000 * 60 * 60 * 24))
                const hours = Math.floor((timeleft % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60))
                const minutes = Math.floor((timeleft % (1000 * 60 * 60)) / (1000 * 60))
                const seconds = Math.floor((timeleft % (1000 * 60)) / 1000)

                // Result is output to the specific element
                daysEl.innerHTML = days
                hoursEl.innerHTML = hours
                minutesEl.innerHTML = minutes
                secondsEl.innerHTML = seconds

                // Display the message when countdown is over
                if (timeleft < 0) {
                    clearInterval(count)
                    daysEl.innerHTML = ""
                    hoursEl.innerHTML = ""
                    minutesEl.innerHTML = ""
                    secondsEl.innerHTML = ""

                    const end = document.getElementById("end")
                    if (end) {
                        end.innerHTML = "00:00:00:00"
                    }
                }
            }, 1000)
        }
    }

    init() {
        this.initCountDown()
    }
}

document.addEventListener("DOMContentLoaded", () => {
    new Countdown().init()
})
