(function ($) {
    "use strict";

    //Scroll back to top
    $(document).ready(function () {

        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;
        })

    });

    // Marquee
    $('.marquee').marquee({
        duration: 20000,
        duplicated: true,
        pauseOnHover: true,
        gap: 0,
        startVisible: true,
        delayBeforeStart: 0,
    });

    // Document Ready
    $(document).ready(function () {

        // menu_toggle
        $('.menu_toggle').on('click', function (event) {
            event.preventDefault();
            $("body").toggleClass('menu_active');
        });

        $('.menu_link').on('click', function (event) {
            $("body").removeClass('menu_active');
        });

        // Toggle dropdown
        $('.tab_selection').on('click', function () {
            $(this).toggleClass('selection_active');
        });

        // Handle tab button click
        $('.tab_btn').on('click', function (event) {
            event.stopPropagation(); 
            var tabbtn_text = $(this).text();
            $(this).closest('.tab_selection')
                .find('.tab_btn_selected span')
                .text(tabbtn_text);
            $(this).closest('.tab_selection').removeClass('selection_active');
        });

        // site_header
        $(document).ready(function () {
            function toggleSticky() {
                if ($(window).scrollTop() >= 100) {
                    $(".site_header").addClass("sticky");
                } else {
                    $(".site_header").removeClass("sticky");
                }
            }

            // Run once on page load (handles refresh case)
            toggleSticky();

            // Run on scroll
            $(window).on("scroll", function () {
                toggleSticky();
            });
        });

        // news_slider
        new Swiper('.testimonial_slider', {
            loop: true,
            spaceBetween: 16,
            slidesPerView: 1,
            // Navigation arrows
            navigation: {
                nextEl: '.testimonial_area .swiper-button-next',
                prevEl: '.testimonial_area .swiper-button-prev',
            },
            // autoplay: { delay: 4000, disableOnInteraction: false },
            a11y: true,
        });

        // nice-select Initialization
        $('.nice-select').niceSelect();

    });

})(jQuery);
