import {Component, Input, OnInit} from '@angular/core';

@Component({
  // tslint:disable-next-line:component-selector
  selector: 'upload-list',
  templateUrl: './upload-list.html'
})
// tslint:disable-next-line:component-class-suffix
export class UploadList implements OnInit {


  constructor() {
    (<any>window).pdfWorkerSrc = '/m/assets/plugins/pdfjs/pdf.worker.js';
    // (window as any).pdfWorkerSrc = '/assets/plugins/pdfjs/pdf.worker.js';
  }

  @Input()
  uploadList: { file_type: '', file_path: '', file_name: '' }[];

  imageList: [] = [];

  zoomStep = [];
  rotation = [];

  ngOnInit(): void {
    for (let i = 0; i < this.uploadList.length; i++) {
      // tslint:disable-next-line:max-line-length
      if (this.uploadList[i].file_type.toLowerCase().indexOf('jpg') >= 0 ||this.uploadList[i].file_type.toLowerCase().indexOf('jpeg') >= 0 || this.uploadList[i].file_type.toLowerCase().indexOf('png') >= 0) {
        // @ts-ignore
        this.imageList.push(this.uploadList[i].file_path);
        this.uploadList.splice(i, 1);
        i--;
      }
    }
  }


  zoomOut(i) {
    this.zoomStep[i] = (this.zoomStep[i] || 1.3) + 0.1;
  }

  zoomIn(i) {
    if (this.zoomStep[i] > 0.5) {
      this.zoomStep[i] = (this.zoomStep[i] || 1.3) - 0.1;
    }
  }

  rotaitionL(i) {
    this.rotation[i] = (this.rotation[i] || 0) - 90;
  }

  rotaitionR(i) {
    this.rotation[i] = (this.rotation[i] || 0) + 90;
  }

  download(url) {
    $('#file_down').attr('href', url);
    document.getElementById('file_down').click();
  }

  fileLoadCompeleted() {

  }

  onError() {

  }
}
