<?php

$GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/lib/swiper/' . $GLOBALS['TL_ASSETS']['SWIPERJS'] . '/css/swiper.min.css';
$GLOBALS['TL_CSS'][] = '/system/modules/eSM_swiper/assets/css/swiper-custom.css';

?>

<script src="/system/modules/eSM_swiper/assets/lib/swiper/<?= $GLOBALS['TL_ASSETS']['SWIPERJS'] ?>/js/swiper.min.js"></script>

<script>
  (function () {
    var cte = document.querySelectorAll(".ce_swiperSliderStart");

    for (var i=0; i<cte.length; i++)
    {
      var e = cte[i].querySelectorAll('.swiper-container')[0];
      var w = e.querySelectorAll('.swiper-wrapper')[0];
      var c = {
        initialSlide: 0,
        speed: 300,
        autoHeight: false,
        effect: 'slide',
        slidesPerView: 1,
        slidesPerGroup: 1,
        preloadImages: true,
        loop: false,
        autoplay: false
      };

      if (w.hasAttribute('data-config'))
      {
        var s = w.getAttribute('data-config').split(',');

        c.speed = parseInt(s[1]);
        c.initialSlide = parseInt(s[2]);

        if (parseInt(s[0]) > 0)
          c.autoplay = {delay: parseInt(s[0]), disableOnInteraction: (parseInt(s[7]) == 1 ? true : false)}

        if (parseInt(s[3]) != 1)
          c.preloadImages = false;

        if (parseInt(s[4]) == 1)
          c.loop = true;

        if (parseInt(s[5]) == 1)
          c.navigation = {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
          };

        if (parseInt(s[6]) == 1)
          c.pagination = {
            el: '.swiper-pagination',
            clickable: true
          };

        if (parseInt(s[8]) == 1)
          c.effect = 'fade';

        if (parseInt(s[9]) > 1)
          c.slidesPerView = parseInt(s[9]);

        if (parseInt(s[10]) > 1)
          c.slidesPerGroup = parseInt(s[10]);

        if (parseInt(s[11]) == 1)
          c.autoHeight = true;

        if (s[12] !== '')
          c.slideClass = s[12];

      }
      if (w.hasAttribute('data-breakpoints'))
      {
        try {
          var breakpoints = JSON.parse(w.getAttribute('data-breakpoints'));
          c.breakpoints = breakpoints;
        } catch (e)
        {
          console.log('Swiper.js: breakpoint data attribute is not valid JSON');
        }
      }
      new Swiper(e,c);
    }
  })();
</script>