import { Component, AfterContentChecked, OnInit, AfterContentInit } from '@angular/core';
import { NbMenuItem } from '@nebular/theme';
import { ApiService } 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 AfterContentInit{
  menu:NbMenuItem[] = [{
    icon: 'image',
    title: 'Raids',
    link: '/frontcraft/raids',
  },{
    icon: 'people',
    title: 'Characters',
    link: '/frontcraft/characters',
  },{
    icon: 'book-open-outline',
    title: 'Loot Rules',
    link: '/frontcraft/rules',
  }]
  
  constructor(
    private loginSvc : ApiService,
    private router : Router
  ){}

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