(function() {
  const SELECTORS = {
    $filters: $('.plp-filters'),
    $filterBar: $('.plp-filters__bar-mobile'),
    $filterModal: $('.filter-modal'),

  }
  const CLASSES = {
    plpFiltersStuck: 'plp-filters__bar-stuck',
  };

  function observeStickyBehavior() {
    const stickyOffset = SELECTORS.$filters.offset().top;

      if (Wick.Responsive.getCurrentBreakpoint() === 'down-sm') {
        if ($(window).scrollTop() >= stickyOffset) {
          SELECTORS.$filterBar.addClass(CLASSES.plpFiltersStuck);
        } else {
          SELECTORS.$filterBar.removeClass(CLASSES.plpFiltersStuck);
        }
      }
  }

  function hideModal() {
    if (Wick.Responsive.getCurrentBreakpoint() !== 'down-sm') {
      SELECTORS.$filterModal.modal('hide');
    }
  }

  $(document).ready(function() {
    $(window).on('scroll', _.debounce(observeStickyBehavior, 100));
    $(window).on('resize', hideModal);
  });
})();
