const searchButton = document.querySelector(".search-wrap button");
searchButton.addEventListener("click", function (e) {
  if(window.innerWidth < 992) return;
  e.preventDefault();
  if (!searchButton.parentElement.parentElement.parentElement.classList.contains('opened')) {
    searchButton.parentElement.parentElement.parentElement.classList.add('opened');
    searchButton.parentElement.previousElementSibling.focus();
  } else {
    if (searchButton.parentElement.previousElementSibling.value != '') {
      searchButton.closest('form').submit();
    } else {
      searchButton.parentElement.parentElement.parentElement.classList.remove('opened');
    }
  }
});
