var Wick = window.Wick || {};

Wick.DefaultStore = {
  HIDDEN_CLASS_NAME: 'd-none',
  el: {
    searchForm: '.search-store',
    $searchInput: $('.search-store #postcode'),
    $btnClear: $('.search-store .btn--clear'),
    $btnSubmit: $('.search-store .btn-search'),
  },
  getPostCode () {
    return Wick.DefaultStore.el.$searchInput.val();
  },
  checkVisibilityOfClearButton () {
    Wick.DefaultStore.el.$btnClear.toggleClass('d-block', Wick.DefaultStore.getPostCode().length > 0);
  },
  updateCollapseState() {
    const dropdowns = $("#openingTimes, #specialTimes, #facilities");
    const btn = $('[data-toggle="collapse"]');

    if (Wick.Responsive.getCurrentBreakpoint() !== 'down-sm') {
      dropdowns.addClass("show");
      if (btn.length) {
        btn.attr("aria-expanded", "true");
      }
    } else {
      dropdowns.removeClass("show");
      if (btn.length) {
        btn.attr("aria-expanded", "false");
      }
    }
  },
  init () {
    Wick.DefaultStore.updateCollapseState();
    Wick.DefaultStore.el.$searchInput.on('input', Wick.DefaultStore.checkVisibilityOfClearButton);
  }
}

$(document).ready(function () {
  Wick.DefaultStore.init();
});
