function kubelioSwiperGalleryInit() {
	const galleries = document.querySelectorAll( ".js-swiper-gallery" );

	galleries.forEach(
		function (gallery) {
			const main      = gallery.querySelector( ".rt-swiper-gallery__featured .swiper" );
			const thumbnail = gallery.querySelector( ".rt-swiper-gallery__thumbnails .swiper" );

			// Guard clause jika elemen tidak ada
			if ( ! main || ! thumbnail) {
				console.warn( "Swiper gallery elements not found", gallery );
				return;
			}

			// Parse options dari data-options
			const dataOptions = gallery.getAttribute( "data-options" );
			const options     = dataOptions ? JSON.parse( dataOptions ) : {};

			// Default values
			const defaults = {
				autoplay: false,
				autoplayDelay: 7000,
				spaceBetween: 10,
				autoHeight: true,
				thumbnailCenter: false,
				thumbnailSlides: 6,
				thumbnailSlidesMobile: 4,
				speed: 300,
			};

			// Merge defaults dengan options
			const config = Object.assign( {}, defaults, options );

			// Thumbnail navigation
			const thumbnailSwiper = new Swiper(
				thumbnail,
				{
					centerInsufficientSlides: config.thumbnailCenter,
					spaceBetween: config.spaceBetween,
					slidesPerView: config.thumbnailSlidesMobile,
					navigation: {
						nextEl: thumbnail.querySelector( ".swiper-button-next" ),
						prevEl: thumbnail.querySelector( ".swiper-button-prev" ),
					},
					breakpoints: {
						768: {
							slidesPerView: config.thumbnailSlides,
						},
					},
					watchSlidesProgress: true,
					freeMode: true,
				}
			);

			// Main swiper
			const mainSwiper = new Swiper(
				main,
				{
					spaceBetween: config.spaceBetween,
					autoplay: config.autoplay ? {
						delay: config.autoplayDelay,
						disableOnInteraction: false
					} : false,
					autoHeight: config.autoHeight,
					navigation: {
						nextEl: main.querySelector( ".swiper-button-next" ),
						prevEl: main.querySelector( ".swiper-button-prev" ),
					},
					pagination: {
						el: main.querySelector( ".swiper-pagination" ),
						type: "fraction",
					},
					thumbs: {
						swiper: thumbnailSwiper,
					},
					speed: config.speed,
				}
			);
		}
	);
}
document.addEventListener( "DOMContentLoaded", kubelioSwiperGalleryInit );