import { Component, EventEmitter, Input, Output } from '@angular/core';
import { RouterExtensions } from '@nativescript/angular';
import { ListViewEventData } from 'nativescript-ui-listview';
import { transitionOptions } from '~/constants/shared.constants';
import { MessageAllWebOutput } from '~/core/entities/output/messageAllWebOutput';
import { LoginDataService } from '~/core/services/login-data.service';

@Component({
    selector: 'MessageSection',
    moduleId: module.id,
    templateUrl: './message-section.component.html',
    styleUrls: ['./_message-section.component.scss']
})
export class MessageSectionComponent {
    @Input() messagesUnread: MessageAllWebOutput[];
    @Output() routeChange = new EventEmitter<boolean>();
    @Output() refreshMessages = new EventEmitter();

    constructor(
        private routerExtensions: RouterExtensions,
        private loginDataSrv: LoginDataService) {
    }

    onNavTap(navRoute: string): void {
        this.routeChange.emit(true);
        setTimeout(() => {
            this.routerExtensions.navigate([navRoute], {transition: transitionOptions});
        }, 10);
    }

    onItemTap(event: ListViewEventData) {
        this.routeChange.emit(true);
        setTimeout(() => {
            this.routerExtensions.navigate(['message/list', this.messagesUnread[event.index].ID], {transition: transitionOptions});
        }, 10);
    }
}
