import {
  Component,
  AfterViewInit,
  ElementRef,
  ViewChild,
  Inject,
} from '@angular/core';
import WebViewer from '@pdftron/webviewer';
import {
  MatDialog,
  MatDialogRef,
  MAT_DIALOG_DATA,
} from '@angular/material/dialog';

@Component({
  selector: 'app-webviewer',
  templateUrl: './webviewer.component.html',
  styleUrls: ['./webviewer.component.css'],
})
export class WebviewerComponent implements AfterViewInit {
  @ViewChild('viewer') viewerRef: any;
  constructor(
    public dialogRef: MatDialogRef<any>,
    @Inject(MAT_DIALOG_DATA) public data: any
  ) {
    console.log(data.url);
  }

  ngAfterViewInit() {
    WebViewer(
      {
        path: '../assets/lib',
        initialDoc: this.data.url,
      },
      this.viewerRef.nativeElement
    ).then((instance) => {
      instance.UI.disableElements([
        'toolbarGroup-Shapes',
        'toolbarGroup-Edit',
        'toolbarGroup-Insert',
        'toolbarGroup-Annotate',
        'toolbarGroup-Forms',
        'notesPanel',
        'viewControlsButton',
        'selectToolButton',
        'toggleNotesButton',
        'freeTextToolGroupButton',
        'crossStampToolButton',
        'checkStampToolButton',
        'dotStampToolButton',
        'rubberStampToolGroupButton',
        'dateFreeTextToolButton',
        'eraserToolButton',
        'signatureToolGroupButton',
        'viewControlsOverlay',
        'toolbarGroup-View',
        'settingsButton',
      ]);
    });
  }
}
