import { Component, Input, EventEmitter, Output, ViewChild, OnInit, OnChanges, SimpleChanges } from '@angular/core';
import { Notification } from '@overflow/commons-typescript/model/notification';
import { Page, PageParams } from '@overflow/commons-typescript/core/model';
import { Paginator } from 'primeng/primeng';

@Component({
    selector: 'of-notification-list',
    templateUrl: './list.component.html',
})
export class NotificationListComponent implements OnChanges {

    @Input() notificationPage: Page<Notification>;
    @Output() pageChange = new EventEmitter<number>();
    @Output() markAll = new EventEmitter();
    @Output() select = new EventEmitter();
    @ViewChild('paginator') paginator: Paginator;

    ngOnChanges(changes: SimpleChanges): void {
        if (changes['notificationPage'] && this.paginator) {
            this.paginator.changePage(this.notificationPage.number);
        }
    }

    onPaginate(e) {
        this.pageChange.emit(e.page);
    }

    onRowSelect(e) {
        this.select.emit(e.data);
    }

    onMarkAllAsRead() {
        this.markAll.emit();
    }
}
