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

$(document)
   .on('change', '.filter-row input, .secondary-filter-item input', function() {
      countActiveFilters();
      wpj.domUtils.resetTimer('countFilters', 1000, function() {
         countActiveFilters();
      });
   })
   .ready(function(){
      countActiveFilters();
   });

function countActiveFilters() {
   $('[data-count-filters]').each(function(i) {
      let $this = $(this);
      let $qty = $this.closest('.filter-row').find('input:checked').length;
      if (!$qty) {
         $qty = $this.closest('.secondary-filter-item').find('.checked').length;
      }
      $this.text($qty);
      if ($this.text() === '0') {
         $this.removeClass('active');
      } else {
         $this.addClass('active');
      }
   });
}
