import { Component } from '@angular/core';
import { EventService } from './event.service';

@Component({
    selector: '[ui-news]',
    templateUrl: './news.component.html',
    styleUrls: ['./news.component.less'],
})
export class NewsComponent {

    constructor(private eventService: EventService) {}

    get visible() {
        return this.eventService.visible && this.count;
    }

    get messages() {
        return this.eventService.messages;
    }

    get count(): number {
        return this.messages.length;
    }

    get newCount(): number {
        return this.eventService.newCount;
    }

    public toggle() {
        if (!this.count) {
            return;
        }

        if (this.eventService.visible) {
            this.eventService.saveMessages();
        }

        this.eventService.visible = !this.eventService.visible;
    }

    public markAsRead(link: string) {
        if (this.eventService.visible) {
            this.eventService.markAsRead(link);
        }
    }
}
