import { Component, ViewChild } from '@angular/core';
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-main-navigation',
  templateUrl: './main-navigation.component.html',
  styleUrl: './main-navigation.component.css',
})
export class MainNavigationComponent {
  @ViewChild('myDrop', { static: false }) myDrop: NgbDropdown;
  private timeout: number;

  onMouseEnter() {
    clearTimeout(this.timeout);
    this.myDrop.open();
  }

  onMouseLeave() {
    this.timeout = setTimeout(() => {
      this.myDrop.close();
    }, 300); // Delay before closing helps if mouse moves to 1px gap for submenu
  }
}
