/**
 * Start Image Carousel widget script
 */

( function( $, elementor ) {

	'use strict';

	var widgetHeroShowcase = function( $scope, $ ) {

		var $HeroShowcase = $scope.find( '.asa-hero-showcase' );
				
        if ( ! $HeroShowcase.length ) {
            return;
        }

		var $HeroShowcaseContainer = $HeroShowcase.find('.swiper-carousel'),
			$settings 		 = $HeroShowcase.data('settings');

		// Add preload settings to prevent image size flash on load
		$settings.preloadImages = true;
		$settings.updateOnImagesReady = true;
		$settings.watchSlidesProgress = true;
		$settings.watchSlidesVisibility = true;

		// Access swiper class
        const Swiper = elementorFrontend.utils.swiper;
        initSwiper();
        
        async function initSwiper() {

			var swiper = await new Swiper($HeroShowcaseContainer, $settings);

			// Show carousel after swiper is initialized
			$HeroShowcase.addClass('asa-swiper-initialized');

			if ($settings.pauseOnHover) {
				 $($HeroShowcaseContainer).hover(function() {
					(this).swiper.autoplay.stop();
				}, function() {
					(this).swiper.autoplay.start();
				});
			}
		};

	};


	jQuery(window).on('elementor/frontend/init', function() {
		elementorFrontend.hooks.addAction( 'frontend/element_ready/asa-hero-showcase.default', widgetHeroShowcase );
	});

}( jQuery, window.elementorFrontend ) );

/**
 * End Image Carousel widget script
 */

