import Swiper from 'https://cdn.jsdelivr.net/npm/swiper@12/swiper-bundle.min.mjs';

export function initSwipers(container = document) {
  const sliders = container.querySelectorAll('.swiper');

  if (sliders.length === 0) {
    return;
  }

  sliders.forEach((sliderElement) => {
    // Éviter de réinitialiser un swiper déjà initialisé
    if (sliderElement.swiper) {
      return;
    }

    const swiper = new Swiper(sliderElement, {
      // Optional parameters
      slidesPerView: 1,
      spaceBetween: 20,
      speed: 600,

      // Touch/Swipe settings
      touchRatio: 1,
      touchAngle: 45,
      grabCursor: true,
      simulateTouch: true,
      allowTouchMove: true,

      // Navigation arrows
      navigation: {
        nextEl: sliderElement.querySelector('.swiper-button-next'),
        prevEl: sliderElement.querySelector('.swiper-button-prev'),
      },

      // Pagination
      pagination: {
        el: sliderElement.querySelector('.swiper-pagination'),
        clickable: true,
      },

      // Keyboard control
      keyboard: {
        enabled: true,
      },

      // Accessibility
      a11y: {
        prevSlideMessage: 'Investigation précédente',
        nextSlideMessage: 'Investigation suivante',
        paginationBulletMessage: 'Aller à l\'investigation {{index}}',
      },
    });
  });
}
