import {Component, OnInit} from '@angular/core';
import {Api} from '../../service/api';

@Component({
    selector: 'v-alarm-bar',
    templateUrl: './alarm-bar.component.html',
    styleUrls: ['./alarm-bar.component.scss'],
})
export class AlarmBarComponent implements OnInit {

    options = [];
    active = 0;

    constructor(private api: Api) {
        this.changeAlarm();
    }

    changeAlarm() {
        setTimeout(() => {
            if (this.active >= this.options.length - 1) {
                this.active = 0;
            } else {
                this.active++;
            }
            this.changeAlarm();
        }, 3000);
    }

    ngOnInit() {
        this.getData();
    }

    getData() {
        this.api.alarm.getLatestAlarm(['', (data) => {
            if (data.constructor === Array) {
                this.options = data;
            }
        }]);
    }
}
