jQuery(document).ready(function($) {
    var meetingStartTime = $(".wemeet_start_time").data("meeting-start-time");
    var countdownDate = new Date(meetingStartTime).getTime();
    const strings = wemeettran.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);

        $(".wemeet_start_time").empty(); // Clear existing content

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

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

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

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

        if (distance < 0) {
            clearInterval(countdown);
            $(".wemeet_start_time").html("");
            $(".wemeet_meeting").show();
            location.reload();
        }
    }, 1000);


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