import {Component, OnInit} from '@angular/core';
import {ApiService} from '../service/api.service';
import {isDebug, debug} from '../utility';
import {Router} from '@angular/router';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage implements OnInit {
  constructor(
      public readonly api: ApiService,
      public readonly router: Router,
  ) {}

  ngOnInit() {
    if ( !this.api.isAuthenticated || this.api.isPublicUser ) {
      if ( isDebug() ) {
        debug('Forcing authentication...');
        setTimeout(() => {
          this.router.navigate(['/login']);
        }, 2000);
      } else {
        this.router.navigate(['/login']);
      }
    }
  }
}
