import { Component, OnInit } from '@angular/core';
import { NavigationEnd, Router } from '@angular/router';
import { RouterExtensions } from '@nativescript/angular';
import { transitionOptions } from '~/constants/shared.constants';

@Component({
    selector: 'Material',
    moduleId: module.id,
    templateUrl: './material.component.html',
    styleUrls: ['./material.component.scss']
})

export class MaterialComponent implements OnInit {
    othersIsLoading: boolean;

    constructor(
        private router: Router,
        private routerExtensions: RouterExtensions
    ) {
        this.router.events.subscribe((val) => {
            if (val instanceof NavigationEnd) {
                if (this.router.url === '/material') {
                    this.othersIsLoading = false;
                }
            }
        });
    }

    ngOnInit(): void {
        this.othersIsLoading = false;
    }

    onLoad() {
        this.othersIsLoading = false;
    }

    goToMaterialUnit() {
        this.othersIsLoading = true;
        setTimeout(() => {
            this.routerExtensions.navigate(['material/materialUnit'], {transition: transitionOptions});
        }, 10);
    }

    goToWarehouseUnit() {
        this.othersIsLoading = true;
        setTimeout(() => {
            this.routerExtensions.navigate(['material/warehouseUnit'], {transition: transitionOptions});
        }, 10);
    }

    goToInventory() {
        this.othersIsLoading = true;
        setTimeout(() => {
            this.routerExtensions.navigate(['material/inventory'], {transition: transitionOptions});
        }, 10);
    }

    goToReservationBorrowed() {
        this.othersIsLoading = true;
        setTimeout(() => {
            this.routerExtensions.navigate(['material/reservationBorrowed'], {transition: transitionOptions});
        }, 10);
    }

    goToReservationLent() {
        this.othersIsLoading = true;
        setTimeout(() => {
            this.routerExtensions.navigate(['material/reservationLent'], {transition: transitionOptions});
        }, 10);
    }

    goToReservation() {
        this.othersIsLoading = true;
        setTimeout(() => {
            this.routerExtensions.navigate(['material/reservation'], {transition: transitionOptions});
        }, 10);
    }
}
