/** @file
 * @author Edouard DUPIN
 * @copyright 2018, Edouard DUPIN, all right reserved
 * @license PROPRIETARY (see license file)
 */
import { Component, OnInit, Input } from '@angular/core';
import { UUID } from 'app/back-api';
//import { ModelResponseHttp } from '@app/service/http-wrapper';
import { DataService } from 'app/service/data';

@Component({
	selector: 'data-image',
	templateUrl: './data-image.html',
	styleUrls: ['./data-image.less']
})
export class ElementDataImageComponent implements OnInit {
	// input parameters
	@Input() id?: UUID;
	cover: string = '';
	/*
		imageCanvas:any;
		@ViewChild('imageCanvas')
		  set mainDivEl(el: ElementRef) {
			if(el !== null && el !== undefined) {
				this.imageCanvas = el.nativeElement;
			}
		}
	*/
	constructor(private dataService: DataService) {

	}
	ngOnInit() {
		this.cover = this.dataService.getThumbnailUrl(this.id);
		/*
		let canvas = this.imageCanvas.nativeElement;
		let ctx = canvas.getContext("2d");
		console.log(`Request thumnail for ---> ${this.id}`);
		this.dataService.getImageThumbnail(this.id)
			.then((result:ModelResponseHttp) => {
				console.log(`plop ---> ${result.status}`);
				const response = result.data as Response;
				response.blob().then((value:Blob) => {
					let img = new Image();
					img.onload = function() {
						//ctx.drawImage(img, 0, 0)
					}
					let imageUrl = URL.createObjectURL(value);
					console.log(`get new image url blob: ${imageUrl}`);
					//img.src = imageUrl;
				})

			}).catch(()=>{
				console.log("plop ---> ");
			});
		//img.src = "../../assets/aCRF-PRV111_CLN-001 v1.4-images/aCRF-PRV111_CLN-001 v1.4-blank_0.jpg";
		//ctx.drawImage(img, 10, 10, 250, 250);
		*/
	}
}
