import { Controller } from '@hotwired/stimulus';

export default class extends Controller<HTMLElement> {
   static targets = [ 'button', 'menu' ];

   declare buttonTarget: HTMLElement;
   declare menuTarget: HTMLElement;

   toggleMenu(): void {
      this.menuTarget.classList.toggle('is-open');
   }

   hideMenu(e): void {
      if (e && (this.menuTarget.contains(e.target) || this.buttonTarget.contains(e.target))) {
         return;
      }
      this.menuTarget.classList.remove('is-open');
   }
}
