var Wick = Wick || {};
Wick.CardColorSlider = (function () {
  var $colorSlider = $('.color-slider');

  var getParameters = function (element) {
    var $elemParent = $(element).parent(),
      count = $(element).find('.swiper-wrapper').children().length,
      isLocked = count <= element.dataset.slides;
    return {
      roundLengths: true,
      navigation: {
        nextEl: $elemParent.find('.color-slider__nav-btn_next')[0],
        prevEl: $elemParent.find('.color-slider__nav-btn_prev')[0]
      },
      slidesPerView: element.dataset.slides,
      loop: !isLocked,
      spaceBetween: 0,
      watchOverflow: true,
      width: element.dataset.width
    }
  };

  var createColorSlider = function (index, element) {
    var slider = new Swiper(element, getParameters(element));
    if (slider.isLocked){
      slider.$el.addClass('is-locked');
    }
  };

  var init = function () {
    $colorSlider.each(createColorSlider);
  };

  init();
})();