import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { RouterExtensions } from '@nativescript/angular';
import { transitionOptions } from '~/constants/shared.constants';
import { EnrollNumberAllPersonOutput } from '~/pages/sts/entities/output/enrollNumberAllPersonOutput';

@Component({
    selector: 'StsSection',
    moduleId: module.id,
    templateUrl: './sts-section.component.html',
    styleUrls: ['./_sts-section.component.scss']
})
export class StsSectionComponent implements OnInit {
    @Input() enrollNumbers: EnrollNumberAllPersonOutput[];
    @Output() routeChange = new EventEmitter<boolean>();

    constructor(
        private routerExtensions: RouterExtensions
    ) {
    }

    ngOnInit() {
    }

    onDisplayCostsStat() {
        this.routeChange.emit(true);
        setTimeout(() => {
            this.routerExtensions.navigate(['/sts/stats'], { transition: transitionOptions });
        }, 10);
    }

    onItemTap(enrollNumber: string) {
        this.routeChange.emit(true);
        setTimeout(() => {
            this.routerExtensions.navigate(['/sts/detail', enrollNumber], { transition: transitionOptions });
        }, 10);
    }

    onBackButton(): void {
        this.routerExtensions.back();
    }

    get statsIcon() {
        return String.fromCharCode(0xf080);
    }
}
