import { tns } from '@shop/engine/node_modules/tiny-slider/src/tiny-slider';

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

if ($('.home-tns').find('.slider-tns').length) {
   const hp_slider = tns({
      container: '.home-tns .slider-tns',
      items: 1,
      slideBy: 1,
      nav: false,
      controls: true,
      controlsText: ['', '']
   });
}

if ($('[data-slider-squares]').length) {
   const squares_slider = tns({
      container: '[data-slider-squares]',
      items: 1.5,
      slideBy: 1,
      nav: false,
      controls: true,
      controlsText: ['', ''],
      gutter: 0,
      loop: false,
      disable: true,
      responsive: {
         544: {
            disable: false,
         },
         768: {
            items: 2,
            gutter: 20,
         },
         1089: {
            items: 3,
         }
      }
   });
}

if ($('[data-tabs="products-tabs"]').length) {
   if ($('#new_products').length) {
      const new_products = tns({
         container: '#new_products [data-products-carousel]',
         items: 2,
         slideBy: 1,
         nav: false,
         loop: false,
         gutter: 10,
         controls: true,
         controlsText: ['', ''],
         responsive: {
            420: {
               items: 2
            },
            768: {
               items: 3,
               gutter: 20
            },
            992: {
               items: 3,
               gutter: 20
            },
            1260: {
               items: 4,
               gutter: 20
            }
         }
      });
   }
   if ($('#bestselling_products').length) {
      const bestselling_products = tns({
         container: '#bestselling_products [data-products-carousel]',
         items: 2,
         slideBy: 1,
         nav: false,
         loop: false,
         gutter: 10,
         controls: true,
         controlsText: ['', ''],
         responsive: {
            420: {
               items: 2
            },
            768: {
               items: 3,
               gutter: 20
            },
            992: {
               items: 3,
               gutter: 20
            },
            1260: {
               items: 4,
               gutter: 20
            }
         }
      });
   }
   if ($('#action_products').length) {
      const action_products = tns({
         container: '#action_products [data-products-carousel]',
         items: 2,
         slideBy: 1,
         nav: false,
         loop: false,
         gutter: 10,
         controls: true,
         controlsText: ['', ''],
         responsive: {
            420: {
               items: 2
            },
            768: {
               items: 3,
               gutter: 20
            },
            992: {
               items: 3,
               gutter: 20
            },
            1260: {
               items: 4,
               gutter: 20
            }
         }
      });
   }
}

$(document).on('click', '[data-show-squares]', function(e) {
   e.preventDefault();
   $(this).closest('.home-squares-wrapper').addClass('opened');
   return false;
});
