import { Component, OnDestroy } from '@angular/core';
import { Router } from '@angular/router';
import { NzContextMenuService, NzDropdownMenuComponent } from 'ng-zorro-antd';
import { NgCortexService } from '@ng-cortex/core';

@Component({
  selector: 'nc-reuse-tab',
  templateUrl: './nc-reuse-tab.component.html',
  styleUrls: ['./nc-reuse-tab.component.scss']
})
export class NcReuseTabComponent implements OnDestroy {

  constructor(
    public ncSrv: NgCortexService,
    private _router: Router,
    private _contextMenuSrv: NzContextMenuService,
  ) { }

  ngOnDestroy() {
    this._contextMenuSrv.close();
  }

  /**
   * 跳转标签
   * @param route 路由地址
   */
  _navigateTo(route: string) {
    this._router.navigateByUrl(route);
  }

  /**
   * 打开菜单
   * @param event 鼠标事件
   * @param menu 菜单模板
   */
  _openMenu(event: MouseEvent, menu: NzDropdownMenuComponent): void {
    this._contextMenuSrv.create(event, menu);
  }

  /**
   * 关闭菜单
   */
  _closeMenu(): void {
    this._contextMenuSrv.close();
  }

}
