jQuery(document).ready(function($) {
    var meetingStartTime = $(".goodmeet-start_time").data("meeting-start-time");
    var countdownDate = new Date(meetingStartTime).getTime();
    const strings = goodmeettran.strings;

    var countdown = setInterval(function() {
        var now = new Date().getTime();
        var distance = countdownDate - now;

        var days = Math.floor(distance / (1000 * 60 * 60 * 24));
        var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
        var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
        var seconds = Math.floor((distance % (1000 * 60)) / 1000);

        $(".goodmeet-start_time").empty(); // Clear existing content

        if (days > 0) {
            var dayLabel = days === 1 ? strings.day : strings.days;
            $(".goodmeet-start_time").append('<span class="goodmeet-countdown-wrapper"><span class="goodmeet-countdown-value">' + days + '</span><span class="goodmeet-countdown-label">' + dayLabel + '</span></span>');
        }

        if (hours > 0 || days > 0) {
            var hourLabel = hours === 1 ? strings.hour : strings.hours;
            $(".goodmeet-start_time").append('<span class="goodmeet-countdown-wrapper"><span class="goodmeet-countdown-value">' + hours + '</span><span class="goodmeet-countdown-label">' + hourLabel + '</span></span>');
        }

        if (minutes > 0 || hours > 0 || days > 0) {
            var minuteLabel = minutes === 1 ? strings.minute : strings.minutes;
            $(".goodmeet-start_time").append('<span class="goodmeet-countdown-wrapper"><span class="goodmeet-countdown-value">' + minutes + '</span><span class="goodmeet-countdown-label">' + minuteLabel + '</span></span>');
        }

        var secondLabel = seconds === 1 ? "Second" : (seconds === 0 ? strings.second : strings.seconds);
        $(".goodmeet-start_time").append('<span class="goodmeet-countdown-wrapper"><span class="goodmeet-countdown-value">' + seconds + '</span><span class="goodmeet-countdown-label">' + secondLabel + '</span></span>');

        if (distance < 0) {
            clearInterval(countdown);
            $(".goodmeet-start_time").html("");
            $(".goodmeet-meeting").show();
            location.reload();
        }
    }, 1000);


    $('.goodmeet-usertime').each(function () {
        var date = new Date($(this).data('time'));
        $(this).html(date.toString());
      });
});
