/** @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 { Season } from 'app/back-api';

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

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

	numberSeason: string;
	count: number;
	covers: string[];
	description: string;

	constructor(
		private dataService: DataService,
		private seasonService: SeasonService,
	) {

	}
	ngOnInit() {
		if (isNullOrUndefined(this.element)) {
			this.numberSeason = undefined;
			this.covers = undefined;
			this.description = undefined;
		}
		this.numberSeason = this.element.name;
		this.description = this.element.description;
		this.covers = this.dataService.getListThumbnailUrl(this.element.covers);
		let self = this;
		this.seasonService.countVideo(this.element.id)
			.then((response) => {
				self.count = response;
			}).catch((response) => {
				self.count = null;
			});
	}
}