(function ($) {
    $(document).ready(function () {
        "use strict";

        //Scroll back to top

        var progressPath = document.querySelector('.progress-wrap path');
        var pathLength = progressPath.getTotalLength();
        progressPath.style.transition = progressPath.style.WebkitTransition = 'none';
        progressPath.style.strokeDasharray = pathLength + ' ' + pathLength;
        progressPath.style.strokeDashoffset = pathLength;
        progressPath.getBoundingClientRect();
        progressPath.style.transition = progressPath.style.WebkitTransition = 'stroke-dashoffset 10ms linear';
        var updateProgress = function () {
            var scroll = $(window).scrollTop();
            var height = $(document).height() - $(window).height();
            var progress = pathLength - (scroll * pathLength / height);
            progressPath.style.strokeDashoffset = progress;
        }
        updateProgress();
        $(window).scroll(updateProgress);
        var offset = 50;
        var duration = 550;
        jQuery(window).on('scroll', function () {
            if (jQuery(this).scrollTop() > offset) {
                jQuery('.progress-wrap').addClass('active-progress');
            } else {
                jQuery('.progress-wrap').removeClass('active-progress');
            }
        });
        jQuery('.progress-wrap').on('click', function (event) {
            event.preventDefault();
            jQuery('html, body').animate({ scrollTop: 0 }, duration);
            return false;
        })

        let match_every = $('.match_every');
        let newDataDom = [];
        match_every.each((index, val) => {
            if (!$(val).data('time')) return
            newDataDom.push($(val));
        });
        setInterval(() => {
            newDataDom?.forEach((val) => {
                if (!$(val).data('time')) return;
                let { hours, minutes, seconds } = getnowTime($(val).data('time'));
                $(val).find('.backwards span').eq(0).text(`${hours}`);
                $(val).find('.backwards span').eq(2).text(`${minutes}`);
                $(val).find('.backwards span').eq(4).text(`${seconds}`);
            });
        }, 1000)

        function getnowTime(time) {
            let currentDate = new Date();
            let otherDate = new Date(time);
            let timeDiff = currentDate.getTime() - otherDate.getTime();
            let totalSeconds = Math.abs(timeDiff) / 1000;
            let hours = Math.floor(totalSeconds / 3600);
            // 将毫秒数转换为秒数
            let seconds = Math.abs(timeDiff) / 1000;
            seconds %= 3600;
            let minutes = String(Math.floor(seconds / 60)).padStart(2, '0');
            seconds = String(Math.floor(seconds % 60)).padStart(2, '0');
            return {
                minutes,
                seconds,
                hours
            }
        }
        // 获取整个文档
        var documentBody = document.body;

        // 添加事件监听器，阻止所有元素的拖放行为
        documentBody.addEventListener('dragstart', function (event) {
            event.preventDefault(); // 阻止拖放开始
        }, { capture: true }); // 使用捕获阶段，这样可以在事件到达目标元素之前阻止它
    });

})(jQuery);