const menuButton = document.querySelector('[data-menu-toggle]');
const nav = document.querySelector('#main-nav');
const searchButton = document.querySelector('[data-search-toggle]');
const searchForm = document.querySelector('[data-search-form]');

menuButton?.addEventListener('click', () => {
  const open = menuButton.getAttribute('aria-expanded') === 'true';
  menuButton.setAttribute('aria-expanded', String(!open));
  nav?.classList.toggle('is-open', !open);
});

searchButton?.addEventListener('click', () => {
  const opening = searchForm?.hasAttribute('hidden');
  searchForm?.toggleAttribute('hidden', !opening);
  if (opening) searchForm?.querySelector('input')?.focus();
});
