// intialization plugins
$(document).ready(function () {

    //animation icon toggler of navbar
    $(`.navbar-toggler`).click(function() {
        $(`.navbar-toggler`).toggleClass(`active`);
    });

    //Wow intit
    wow = new WOW({
        boxClass: 'wow',
        animateClass: 'animated',
        offset: 200,
        mobile: true,
        live: false
    });
    wow.init();

    //fancybox
    $("[data-fancybox]").fancybox({
        selector: '[data-fancybox="images"]',
        // loop: true
    });

    //  loader 
    // $(window).on("load", function() {
    //     $("#preloader").addClass("isdone");
    // });

    // plus & minus btns 
    $(".plus-btn").click(function() {
        let input = $(this).siblings(".qt-input");
        let value = parseInt(input.val());
        input.val(value + 1);
    });
    $(".minus-btn").click(function() {
        let input = $(this).siblings(".qt-input");
        let value = parseInt(input.val());
        if (value > 1) {
            input.val(value - 1);
        }
    });

    $(".fav-btn").click(function() {
        $(this).toggleClass("active");
    });

    // ------------ SHOW HED PASS ----------
    $(".show_hide_password .show_pass").on('click', function(event) {
        event.preventDefault();
        if($(this).siblings("input").attr("type") == "text"){
            $(this).siblings("input").attr('type', 'password');
            $(this).addClass( "fa-eye-slash" );
            $(this).removeClass( "fa-eye" );
        }else if($(this).siblings("input").attr("type") == "password"){
            $(this).siblings("input").attr('type', 'text');
            $(this).removeClass( "fa-eye-slash" );
            $(this).addClass( "fa-eye" );
        }
    });

    // ------------ modal countdown ----------
    $(document).ready(function() {
        function startCountdown(duration) {
            let timer = duration, minutes, seconds;
            const countdownElement = document.querySelector('.code-countdown');
            const resendBtn = document.getElementById('resend-btn');
            const interval = setInterval(() => {
                minutes = parseInt(timer / 60, 10);
                seconds = parseInt(timer % 60, 10);
        
                // Format time with leading zeros
                seconds = seconds < 10 ? "0" + seconds : seconds;
                countdownElement.textContent = minutes + ":" + seconds;

                if (--timer < 0) {
                    clearInterval(interval);
                    countdownElement.textContent = "";
                    
                    // Remove the 'd-none' class from the resend button when time is up
                    resendBtn.classList.remove('d-none');
                }
            }, 1000);
        }

        startCountdown(120);

    });

});

// navbar-fixed-top
$(function () {
    $(document).scroll(function () {
        var $nav = $(".scrolled_nav");
        $nav.toggleClass('scrolled', $(this).scrollTop() > $nav.height());
    });
});


// Swiper
$(document).ready(function () {
    //////////////////// categ_swiper  ////////////////////
    var swiper = new Swiper('.categ_sec .categ_swiper', {
        // loop: true,
        speed: 900,
        slidesPerView: 1,
        spaceBetween: 15,
        // autoplay: {
        //     delay: 2500,
        // },
        navigation: {
            nextEl: '.categ_sec .swiper-button-next',
            prevEl: '.categ_sec .swiper-button-prev',
        },
        pagination: {
            el: '.categ_sec .swiper-pagination',
            clickable: true
        },
        breakpoints: {
            640: {
                slidesPerView: 2,
                spaceBetween: 20,
            },
            768: {
                slidesPerView: 3,
                spaceBetween: 20,
            },
            1024: {
                slidesPerView: 4,
                spaceBetween: 20,
            },
        }
    });

    //////////////////// prods_swiper  ////////////////////
    var swiper = new Swiper('.products_sec .prods_swiper', {
        // loop: true,
        speed: 900,
        slidesPerView: 1,
        spaceBetween: 15,
        // autoplay: {
        //     delay: 2500,
        // },
        navigation: {
            nextEl: '.products_sec .swiper-button-next',
            prevEl: '.products_sec .swiper-button-prev',
        },
        pagination: {
            el: '.products_sec .swiper-pagination',
            clickable: true
        },
        breakpoints: {
            640: {
                slidesPerView: 2,
                spaceBetween: 20,
            },
            768: {
                slidesPerView: 3,
                spaceBetween: 20,
            },
            1024: {
                slidesPerView: 5,
                spaceBetween: 20,
                allowTouchMove: false,
                preventClicks: false
            },
        }
    });


    //////////////////// feedback_swiper  ////////////////////
    var swiper = new Swiper('.feedback_sec .feedback_swiper', {
        // loop: true,
        speed: 900,
        slidesPerView: 1,
        spaceBetween: 15,
        // autoplay: {
        //     delay: 2500,
        // },
        navigation: {
            nextEl: '.feedback_sec .swiper-button-next',
            prevEl: '.feedback_sec .swiper-button-prev',
        },
        pagination: {
            el: '.feedback_sec .swiper-pagination',
            clickable: true
        },
        breakpoints: {
            640: {
                slidesPerView: 2,
                spaceBetween: 20,
            },
            768: {
                slidesPerView: 3,
                spaceBetween: 20,
            },
            1024: {
                slidesPerView: 3,
                spaceBetween: 20,
                allowTouchMove: false,
                preventClicks: false
            },
        }
    });

    //////////////////// feedback_swiper  ////////////////////
    var swiper = new Swiper('.feedback-tab .feedback_sec .testi-slider', {
        // loop: true,
        speed: 900,
        slidesPerView: 1,
        spaceBetween: 15,
        autoplay: {
            delay: 5000,
        },
        observer: true,
        observeParents: true,
        navigation: {
            nextEl: '.feedback_sec .swiper-button-next',
            prevEl: '.feedback_sec .swiper-button-prev',
        },
        pagination: {
            el: '.feedback_sec .swiper-pagination',
            clickable: true
        },
        breakpoints: {
            640: {
                slidesPerView: 2,
                spaceBetween: 20,
            },
            768: {
                slidesPerView: 3,
                spaceBetween: 20,
            },
            1024: {
                slidesPerView: 1,
                spaceBetween: 20,
                allowTouchMove: false,
                preventClicks: false
            },
        }
    });
        

    //////////////////// partners_swiper  ////////////////////
    var swiper = new Swiper('.partners_sec .partners_swiper', {
        // loop: true,
        speed: 900,
        slidesPerView: 2,
        spaceBetween: 15,
        // autoplay: {
        //     delay: 2500,
        // },
        navigation: {
            nextEl: '.partners_sec .swiper-button-next',
            prevEl: '.partners_sec .swiper-button-prev',
        },
        pagination: {
            el: '.partners_sec .swiper-pagination',
            clickable: true
        },
        breakpoints: {
            640: {
                slidesPerView: 2,
                spaceBetween: 20,
            },
            768: {
                slidesPerView: 3,
                spaceBetween: 20,
            },
            1024: {
                slidesPerView: 5,
                spaceBetween: 20,
            },
        }
    });
    //////////////////// Swiper  ////////////////////
    // var swiper = new Swiper(' .swiper-container', {
    //     // loop: true,
    //     speed: 900,
    //     slidesPerView: 1,
    //     spaceBetween: 15,
    //     // autoplay: {
    //     //     delay: 2500,
    //     // },
    //     //In Tabs
    //     // observer: true,
    //     // observeParents: true,
    //     navigation: {
    //         nextEl: '.swiper-button-next',
    //         prevEl: '.swiper-button-prev',
    //     },
    //     pagination: {
    //         el: '.swiper-pagination',
    //         clickable: true
    //     },
    //     breakpoints: {
    //         640: {
    //             slidesPerView: 2,
    //             spaceBetween: 20,
    //         },
    //         768: {
    //             slidesPerView: 3,
    //             spaceBetween: 20,
    //         },
    //         1024: {
    //             slidesPerView: 5,
    //             spaceBetween: 20,
    //             // Prevent swiper in lg screens
    //             // allowTouchMove: false,
    //             // preventClicks: false
    //         },
    //     }
    // });

});


