(function ($) {
    "use strict";

    function heroSliderOne() {

        $("[data-background").each(function() {
            $(this).css("background-image", "url( " + $(this).attr("data-background") + "  )");
        });

        $(document).ready(function () {
            function sliderAnimations(elements) {
                var animationEndEvents = "webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend";
                elements.each(function () {
                    var $this = $(this);
                    var $animationDelay = $this.data("delay");
                    var $animationDuration = $this.data("duration");
                    var $animationType = "logistec-animation " + $this.data("animation");
                    $this.css({
                        "animation-delay": $animationDelay,
                        "-webkit-animation-delay": $animationDelay,
                        "animation-duration": $animationDuration,
                    });
                    $this.addClass($animationType).one(animationEndEvents, function () {
                        $this.removeClass($animationType);
                    });
                });
            }
            var sliderOptions = {
                speed: 1000,
                autoplay: false,
                delay: 1000,
                disableOnInteraction: false,
                initialSlide: 0,
                parallax: false,
                mousewheel: false,
                loop: true,
                grabCursor: true,
                navigation: {
                    nextEl: ".slider-arrow .slider-next",
                    prevEl: ".slider-arrow .slider-prev",
                },
                pagination: {
                    el: ".logistec-swiper-pagination",
                    clickable: true,
                },
            };
            sliderOptions.on = {
                slideChangeTransitionStart: function () {
                    var swiper = this;
                    var animatingElements = $(swiper.slides[swiper.activeIndex]).find("[data-animation]");
                    sliderAnimations(animatingElements);
                },

                resize: function () {
                    this.update();
                },
            };

            var swiper = new Swiper(".logistec-slider", sliderOptions);
        });
    }
    
    function heroSliderTwo() { 

        $("[data-background").each(function() {
            $(this).css("background-image", "url( " + $(this).attr("data-background") + "  )");
        });

        $(document).ready(function () {
            function sliderAnimations(elements) {
                var animationEndEvents = "webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend";
                elements.each(function () {
                    var $this = $(this);
                    var $animationDelay = $this.data("delay");
                    var $animationDuration = $this.data("duration");
                    var $animationType = "logistec-animation " + $this.data("animation");
                    $this.css({
                        "animation-delay": $animationDelay,
                        "-webkit-animation-delay": $animationDelay,
                        "animation-duration": $animationDuration,
                    });
                    $this.addClass($animationType).one(animationEndEvents, function () {
                        $this.removeClass($animationType);
                    });
                });
            }
            var sliderOptions = {
                speed: 1000,
                autoplay: false,
                delay: 1000,
                disableOnInteraction: false,
                initialSlide: 0,
                parallax: false,
                mousewheel: false,
                loop: true,
                grabCursor: true,
                navigation: {
                    nextEl: ".slider-arrow .slider-next",
                    prevEl: ".slider-arrow .slider-prev",
                },
                pagination: {
                    el: ".logistec-swiper-pagination",
                    clickable: true,
                },
            };
            sliderOptions.on = {
                slideChangeTransitionStart: function () {
                    var swiper = this;
                    var animatingElements = $(swiper.slides[swiper.activeIndex]).find("[data-animation]");
                    sliderAnimations(animatingElements);
                },

                resize: function () {
                    this.update();
                },
            };

            var swiper = new Swiper(".logistec-slider", sliderOptions);
        });
    }
    
    // Elementor Slider Activation
    $(window).on('elementor/frontend/init', function() {
        elementorFrontend.hooks.addAction('frontend/element_ready/logistec_hero_slider_one.default', heroSliderOne);
        elementorFrontend.hooks.addAction('frontend/element_ready/logistec_hero_slider_two.default', heroSliderTwo);
    });
})(jQuery);
