import { Component, OnInit } from '@angular/core';
import { ModalController, NavParams } from '@ionic/angular';
import { ProcessesService } from 'src/app/services/processes.service';
import { ThemeService } from 'src/app/services/theme.service'


@Component({
  selector: 'app-document-viewer',
  templateUrl: './document-viewer.page.html',
  styleUrls: ['./document-viewer.page.scss'],
})
export class DocumentViewerPage implements OnInit {

  pdfSrc = null;
  task = null
  DocId = null
  fileName = ''
  link = ''

  constructor(
    private modalController: ModalController,
    private navParams: NavParams,
    public processes: ProcessesService,
    public ThemeService: ThemeService) {
      
      this.task = this.navParams.get('task') || null;
      this.DocId = this.navParams.get('DocId');

      this.pdfSrc = 'https://equilibrium.dyndns.info/FileShare/pdfjs/web/viewer.html?file='
      
    }
  
  ngOnInit() {

    this.processes.getFileBase64(this.DocId).subscribe((res: any) => {
      
      console.log(res)
      this.pdfSrc= 'data:application/pdf;base64,'+ res.file
      this.fileName = res.name

    })

  }

  close() {
    this.modalController.dismiss();
  }
}
