import { Component, AfterContentChecked, OnInit } from '@angular/core';
import { NbMenuItem } from '@nebular/theme';
import { LoginApiService } from '../services/login-api';
import { Router } from '@angular/router';

@Component({
  selector: 'page-layout',
  template: `

    <ngx-one-column-layout>
    <nb-menu [items]="menu"></nb-menu>

      <router-outlet></router-outlet>
    </ngx-one-column-layout>
  `,
})
export class PagesLayoutComponent implements OnInit{
  menu:NbMenuItem[] = [{
    icon: 'people-outline',
    title: 'People'
  },{
    icon: 'clock-outline',
    title: 'Raids'
  }]
  
  constructor(
    private loginSvc : LoginApiService,
    private router : Router
  ){}

  ngOnInit() : void {
    this.loginSvc.checkLogin().then(loggedin => {
      if(!loggedin){
        this.router.navigateByUrl("/auth")
      }
    });
  }
}