import { Component, HostListener } from '@angular/core';
import { MatDialogRef } from '@angular/material/dialog';

@Component({
  selector: 'app-nano-dialog-base',
  template: '',
})
export class NanoDialogBaseComponent<ChildDialogComponent> {
  constructor(public dialogRef: MatDialogRef<ChildDialogComponent>) {}

  @HostListener('document:keydown.escape', ['$event'])
  onKeydownHandler(event: KeyboardEvent) {
    this.dialogRef.close();
  }

  @HostListener('window:popstate', ['$event'])
  onPopState(event) {
    this.dialogRef.close();
    event.stopPropagation();
  }
}
