$(document).ready(function() {

    var wind = $(window);

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


    // ---------- add adress -----------
    $("#ad-adress-btn").on("click", function(){
        $("#ad-adress").removeClass("d-none")
    })
    $("#cancel-adress-btn").on("click", function(){
        $("#ad-adress").addClass("d-none")
    })

    // ---------- to top -----------
    $('.to-top').click(function() {
        $('html, body').animate({
            scrollTop: 0
        }, 1000);
        return false;
    });


    // ------------ SHOW HIDE PASS ----------
    $(document).ready(function() {
        $(".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" );
            }
        });
    });


    // ------------ increase products -----------
    $(".qt-plus").click(function() {
        $(this).parent().children(".qt").html(parseInt($(this).parent().children(".qt").html()) + 1);
    });
    $(".qt-minus").click(function() {

        child = $(this).parent().children(".qt");

        if (parseInt(child.html()) > 1) {
            child.html(parseInt(child.html()) - 1);
        }

        $(this).parent().children(".full-price").addClass("minused");

    });


});


// ------------ swiper sliders -----------
$(document).ready(function() {

    // top products slider 
    var swiper = new Swiper('.top-products .products-slider', {
        slidesPerView: 5,
        spaceBetween: 24,
        // centeredSlides: true,
        speed: 1500,
        pagination: {
            el: '.top-products .swiper-pagination',
            clickable: true,
        },
        navigation: {
            nextEl: '.top-products .swiper-button-next',
            prevEl: '.top-products .swiper-button-prev',
        },
        mousewheel: false,
        keyboard: true,
        autoplay: {
            delay: 5000,
        },
        loop: true,
        breakpoints: {
            0: {
                slidesPerView: 1,
            },
            480: {
                slidesPerView: 2,
            },
            787: {
                slidesPerView: 3,
            },
            991: {
                slidesPerView: 4,
            },
            1200: {
                slidesPerView: 4,
            }
        }
    });

});


// ------------ gsap scripts -----------
$(function () {
    gsap.registerPlugin(ScrollTrigger, ScrollSmoother);

    const smoother = ScrollSmoother.create({
        content: "#scrollsmoother-container",
        smooth: 1.5,
        normalizeScroll: true,
        ignoreMobileResize: true,
        effects: true,
    });

    // smoother.effects("img", { speed: "auto" });

    let headings = gsap.utils.toArray(".js-title").reverse();
    headings.forEach((heading, i) => {
        let headingIndex = i + 1;
        let mySplitText = new SplitText(heading, { type: "chars" });
        let chars = mySplitText.chars;

        chars.forEach((char, i) => {
            smoother.effects(char, { lag: (i + headingIndex) * 0.1, speed: 1 });
        });
    });


    let splitTextLines = gsap.utils.toArray(".js-splittext-lines");

    splitTextLines.forEach(splitTextLine => {
        const tl = gsap.timeline({
            scrollTrigger: {
                trigger: splitTextLine,
                start: 'top 90%',
                duration: 2,
                end: 'bottom 60%',
                scrub: false,
                markers: false,
                toggleActions: 'play none none none'
                // toggleActions: 'play none play reset'
            }
        });

        const itemSplitted = new SplitText(splitTextLine, { type: "lines" });
        gsap.set(splitTextLine, { perspective: 400 });
        itemSplitted.split({ type: "lines" })
        // tl.from(itemSplitted.lines, { y: 100, delay: 0.2, opacity: 0, stagger: 0.1, duration: 1, ease: 'inOut' });
        // tl.from(itemSplitted.lines, { y: 100, opacity: 0, stagger: 0.05, duration: 1, ease: 'back.inOut' });
        tl.from(itemSplitted.lines, { duration: 1, delay: 0.5, opacity: 0, rotationX: -50, force3D: false, transformOrigin: "top center -50", stagger: 0.1 });
    });



    // sticky position 
    gsap.utils.toArray(".position-sticky").forEach((sticky) => {
    const parent = sticky.closest("section");
        ScrollTrigger.create({
            trigger: parent,
            start: "top top",
            end: "bottom bottom",
            pin: sticky,
            pinSpacing: false,
            scrub: false
        });

    });



});
