import { Component, OnInit } from '@angular/core';
import { Slide } from './slide.model';
import { CarouselService } from './carousel.service';

@Component({
    moduleId: module.id,
    selector: 'rtv-carousel',
    templateUrl: 'carousel.component.html',
    styleUrls: ['carousel.component.css'],
})
export class CarouselComponent implements OnInit {
    public slides: Slide[] = [];
    public interval: number = 5500;
    errorMessage: string;

    public constructor(
        private _carouselService: CarouselService
    ) { }

    ngOnInit() {
        this.getSlides();
    }

    getSlides() {
        this._carouselService.getSlides().
            subscribe(slides => this.slides = slides, error => this.errorMessage = <any>error);
    }

    getDelay(index: number) {
        return (index * this.interval / 1000) + 's';
    }

    getDuration() {
        return (this.interval * this.slides.length / 1000) + 's';
    }
}
