$(function () {
    const accordionBtns = document.querySelectorAll(".item-header");

    accordionBtns.forEach((accordion) => {
        accordion.onclick = function () {
            this.classList.toggle("active");

            let content = this.nextElementSibling;
            console.log(content);

            if (content.style.maxHeight) {
                //this is if the accordion is open
                content.style.maxHeight = null;
            } else {
                //if the accordion is currently closed
                content.style.maxHeight = content.scrollHeight + "px";
                console.log(content.style.maxHeight);
            }
        };
    });

    function stickyHeader() {
        if ($('.webpulse-soluction').length) {
            var strickyScrollPos = 100;
            if ($(window).scrollTop() > strickyScrollPos) {
                $('.webpulse-soluction').addClass('stricky-fixed');
            }
            else if ($(this).scrollTop() <= strickyScrollPos) {
                $('.webpulse-soluction').removeClass('stricky-fixed');
            }
        };
    }

    jQuery(window).on('scroll', function () {
        (function ($) {
            stickyHeader();
        })(jQuery);
    });


    if ($('.web-pulse-navigation-wps').length) {
        $('.web-pulse-navigation-wps .navbar button').on('click', function () {
            $('.web-pulse-navigation-wps .web-p-u-l-s-e-menu').slideToggle();
            return false;
        });



        $('.web-pulse-navigation-wps .cs-submenu').children('a').append(function () {
            return '<button class="dropdown-expander"><i class="fa fa-chevron-down "></i></button>';
        });
        $('.web-pulse-navigation-wps .web-p-u-l-s-e-menu .dropdown-expander').on('click', function () {
            $(this).parent().parent().children('.cs-dropdown').slideToggle();
            console.log($(this).parents('li'));
            return false;
        });
    }

    if (document.documentElement.clientWidth < 980) {
        $(document).click(function (e) {
            if (!$(e.target).closest('.web-pulse-navigation-wps .navbar button').length) {
                $('.web-p-u-l-s-e-menu').stop(true).slideUp();
            }
        });
    }

    var homeSlider = $("#slider1");
    homeSlider.owlCarousel({
        loop: true,
        margin: 0,
        navSpeed: 500,
        nav: true,
        navText: ['<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/></svg>', '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/></svg>'],
        autoplay: true,
        dots: false,
        animateOut: "fadeOut",
        items: 1
    });

    var populerProducts = $("#populer_products");
    populerProducts.owlCarousel({
        loop: false,
        rewind: true,
        margin: 20,
        navSpeed: 500,
        nav: true,
        navText: ['<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/></svg>', '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/></svg>'],
        autoplay: true,
        dots: false,
        items: 3,
        responsiveClass: true,
        responsive: {
            0: {
                items: 1
            },
            600: {
                items: 1,
            },
            1024: {
                items: 3
            },
            1100: {
                items: 3
            }
        }
    });

    var populerblog = $("#populer_blogs");
    populerblog.owlCarousel({
        loop: false,
        rewind: true,
        margin: 20,
        navSpeed: 500,
        nav: true,
        navText: ['<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/></svg>', '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/></svg>'],
        autoplay: true,
        dots: false,
        items: 3,
        responsiveClass: true,
        responsive: {
            0: {
                items: 1
            },
            600: {
                items: 1,
            },
            1024: {
                items: 3
            },
            1100: {
                items: 3
            }
        }
    });


    var populerblog = $("#brand-logo-carousel");
    populerblog.owlCarousel({
        loop: false,
        margin: 20,
        navSpeed: 500,
        nav: true,
        navText: ['<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/></svg>', '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/></svg>'],
        autoplay: true,
        dots: false,
        items: 5,
        responsiveClass: true,
        responsive: {
            0: {
                items: 2
            },
            600: {
                items: 2,
            },
            1024: {
                items: 5
            },
            1100: {
                items: 5
            }
        }
    });


    function isNumberKey(evt) {
        //var e = evt || window.event;
        var charCode = (evt.which) ? evt.which : evt.keyCode
        if (charCode != 46 && charCode > 31
            && (charCode < 48 || charCode > 57))
            return false;
        return true;
    }

    function ValidateAlpha(evt) {
        var keyCode = (evt.which) ? evt.which : evt.keyCode
        if ((keyCode < 65 || keyCode > 90) && (keyCode < 97 || keyCode > 123) && keyCode != 32)

            return false;
        return true;
    }

    var testimonial = $("#populer_testimonial");
    testimonial.owlCarousel({
        loop: false,
        margin: 20,
        navSpeed: 500,
        nav: true,
        navText: ['<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M11.354 1.646a.5.5 0 0 1 0 .708L5.707 8l5.647 5.646a.5.5 0 0 1-.708.708l-6-6a.5.5 0 0 1 0-.708l6-6a.5.5 0 0 1 .708 0z"/></svg>', '<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="currentColor" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"/></svg>'],
        autoplay: true,
        dots: false,
        items: 2,
        responsiveClass: true,
        responsive: {
            0: {
                items: 1
            },
            600: {
                items: 1,
            },
            1024: {
                items: 2
            },
            1100: {
                items: 2
            }
        }
    });

});

