/** @file
 * @author Edouard DUPIN
 * @copyright 2018, Edouard DUPIN, all right reserved
 * @license PROPRIETARY (see license file)
 */
import { Component, OnInit, Input } from '@angular/core';
import { isNullOrUndefined } from '@kangaroo-and-rabbit/kar-cw';
import { Type } from 'app/back-api';

import { TypeService, DataService } from 'app/service';

@Component({
	selector: 'app-element-type',
	templateUrl: './element-type.html',
	styleUrls: ['./element-type.less']
})
export class ElementTypeComponent implements OnInit {
	// input parameters
	@Input() element: Type;

	public name: string = 'rr';
	public description: string;

	public countVideo: number;

	public covers: string[];

	constructor(
		private dataService: DataService,
		private typeService: TypeService,
	) {

	}
	ngOnInit() {
		if (isNullOrUndefined(this.element)) {
			this.name = 'Not a media';
			this.description = undefined;
			this.countVideo = undefined;
			this.covers = undefined;
			return;
		}
		let self = this;
		self.name = this.element.name;
		self.description = this.element.description;
		self.covers = self.dataService.getListThumbnailUrl(this.element.covers);

		this.typeService.countVideo(this.element.id)
			.then((response: number) => {
				self.countVideo = response;
			}).catch(() => {
				self.countVideo = 0;
			});
	}
}
