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

    });

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

        // menu_toggle
        $('.menu_toggle').on('click', function (event) {
            event.preventDefault();
            $("body").toggleClass('menu_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();
            });
        });

        // heroSlider
        const swiper = new Swiper('.heroSlider', {
            loop: true,
            slidesPerView: 1,

            effect: 'fade',
            fadeEffect: {
                crossFade: true,
            },

            autoplay: {
                delay: 3000,
                disableOnInteraction: false, 
            },

            pagination: {
                el: '.swiper-pagination',
                clickable: true,
            },
        });

        // language-select
        $('.language-select').on('click', function () {
            $('.language-select').removeClass('active');
            $(this).addClass('active');
        });

        // megamenu1-totgle-btn
        $('.megamenu1-totgle-btn').on('click', function () {
            $('.mega-menu-one').toggleClass('show');
        });

        // menutwo-dropdown-btn
        $('.menutwo-toggle').on('click', function () {
            $('.mega-menu-two').toggleClass('show');
        });

        // lenis
        $(document).ready(function () {

            const lenis = new Lenis({
                duration: 1.2,
                easing: function (t) {
                    return 1 - Math.pow(1 - t, 3);
                },
                smooth: true
            });

            function raf(time) {
                lenis.raf(time);
                requestAnimationFrame(raf);
            }

            requestAnimationFrame(raf);

        });

    });

})(jQuery);
