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

// kvůli search
const WpjTabs = require('@assets/js/wpj.tabs.js');
new WpjTabs('[data-tabs="search-results"]');

/*// responzivni filtr
$('[data-filter-btn]').on('click', function(e) {
   e.preventDefault();

   $('.category-side').toggleClass('active');
   $('body').toggleClass('scroll-disable');
});*/

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
         }
      }
   });
}

wpj.domUtils.initOpeners();

$('.secondary-check').on('click', function() {
   $(this).toggleClass('checked');
});


$(document)
   .ready(function() {
      $('.filter-form-inner').find('[data-opener]').click();
   })
   .on('click', function(e) {
      if (!$(e.target).closest('.secondary-filter-item').length && !$(e.target).closest('.custom-control').length) {
         $('.filter-top [data-opener].active').click();
      }
   })
   .on('click', '.secondary-filter-item .filter-label[data-opener]', function(e) {
      $(this)
         .closest('.secondary-filter-item')
         .siblings('.secondary-filter-item')
         .find('.filter-label[data-opener].active')
         .removeClass('active')
         .nextAll('.opener-content')
         .removeClass('active').slideUp();

      $('.filter-sort-wrapper [data-opener]')
         .removeClass('active')
         .nextAll('.opener-content.active')
         .toggleClass('active').slideUp();
   })
   .on('click', '.filter-sort-wrapper [data-opener]', function(e) {
      $(this)
         .closest('.filter-top')
         .find('.custom-filters .filter-label[data-opener].active')
         .removeClass('active')
         .nextAll('.opener-content')
         .removeClass('active').slideUp();
   })
   .on('click', '[data-toggle="filters"]', function(e) {
      $('.custom-filters [data-opener].active').click();
      $('[data-filters]').toggleClass('active');
      $('body').toggleClass('filter-active');
      return false;
   })
   .on('click', '[data-scroll-top]', function() {
      wpj.domUtils.scrollTo($('body'))
   });
