import { Component, Input, Output, EventEmitter, OnInit, ViewChild } from '@angular/core';
import { NzContextMenuService, NzDropdownMenuComponent } from 'ng-zorro-antd';

@Component({
  selector: 'app-tab-context-menu',
  template: `
    <div class="context-menu" [ngStyle]="{left: x + 'px', top: y + 'px'}">
      <nz-dropdown-menu #menu="nzDropdownMenu">
        <ul nz-menu class="context-menu-list">
          <li nz-menu-item (click)="closeOthers.emit()">关闭其他</li>
        </ul>
      </nz-dropdown-menu>
    </div>
  `,
  styles: [`.ant-dropdown-menu-item, .ant-dropdown-menu-submenu-title{font-size:12px;line-height:1;width: 120px;}`]
})
export class TabContextMenuComponent implements OnInit {
  @Input() x = 0;
  @Input() y = 0;
  @Input() event:MouseEvent;
  @Output() closeOthers = new EventEmitter<void>();
  @ViewChild('menu', { static: true}) menu: NzDropdownMenuComponent;
  constructor(
    private nzContextMenuService: NzContextMenuService,
  ){}

  ngOnInit(): void {
    this.nzContextMenuService.create(this.event, this.menu);
  }
}
