import { DataWithFileUploaded } from './../../interface/data-with-file-uploaded';
import { Component, OnInit } from '@angular/core';
import {ModalController} from '@ionic/angular';

@Component({
  selector: 'app-parere-modal',
  templateUrl: './parere-modal.component.html',
  styleUrls: ['./parere-modal.component.scss'],
})

export class ParereModalComponent implements OnInit {

  constructor(private modalController: ModalController) { 
    result = {dati: null, file: null};
  }

  ngOnInit() {}

  loadFile()
  {
    var element : HTMLInputElement = document.querySelector('input[type=file]');
    var file: Blob    = element.files[0];
    var reader  = new FileReader();

    reader.onloadend = function () {
      result.file = reader.result;
    };

    /*reader.addEventListener("load", function () {
      result.file = reader.result;
    }, false);*/

    if (file) {
      reader.readAsDataURL(file);
    }
  }

  async dismiss(form)
  {
    result.dati = form.value;
    await this.modalController.dismiss(result);
  }

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

  fileName;

}

var result: DataWithFileUploaded;
