

import ProductSets from '@assets[shared]/js/wpj.productSets.js';

if ($('[data-sets="wrapper"]').length) {
   new ProductSets();
}

if (MODULES.WATCHDOG) {
   import('@assets/js/wpj.watchdog.js').then(wpjWatchdog => {
      wpjWatchdog.initWatchdog();
   });
}

if (typeof initProductGallerySlider === 'undefined' && $('#product-gallery').length) {
   import('@assets/js/wpj.product.helpers.js').then(productHelpers => {
      if (typeof initProductGallerySlider === 'undefined') {
         productHelpers.initProductGallerySlider();
      }
   });
}

wpj.domUtils.initOpeners();


const WpjTabs = require('@assets/js/wpj.tabs.js');
new WpjTabs('[data-tabs="product-tabs"]');

if (typeof initProductGallerySlider === 'undefined' && $('#product-gallery').length) {
   import('@assets/js/wpj.product.helpers.js').then(productHelpers => {
      if (typeof initProductGallerySlider === 'undefined') {
         productHelpers.initProductGallerySlider();
      }
   });
}

if ($('#related').length ) {
   import('@assets/js/wpj.carousel.js').then(wpjCarousel => {
      if ($('#related').length) {
         $('#related').wpjCarousel({
            itemsOnPage: 1.5,
            gutter: 20,
            controlsText: ['<span class="fc icons_caret-left"></span>', '<span class="fc icons_caret-right"></span>'],
            responsive: {
               544: {
                  itemsOnPage: 2.5,
                  gutter: 20
               },
               768: {
                  itemsOnPage: 3.5,
                  gutter: 20
               },
               1260: {
                  itemsOnPage: 4,
                  gutter: 20
               }
            }
         });
      }
   });
}

$('[data-more-reviews]').on('opened', function() {
   var $this = $(this),
      $btn = $('[data-opener="[data-more-reviews]"]'),
      $more = $btn.data('text-show'),
      $less = $btn.data('text-hide');

   if (!$this.is('.active')) {
      $btn.text($more);
   } else {
      $btn.text($less);
   }
});

