import { Injectable } from '@angular/core';

import { Roots } from '@enums/root.enum';
import { NavController } from '@ionic/angular';
import { StateManagementService } from '@services/state-management.service';

@Injectable({
  providedIn: 'root'
})
export class AuthGuard  {

  constructor(
    private navController: NavController,
    private stateManagementService: StateManagementService
  ) { }

  async canActivate(): Promise<boolean> {
    const token = await this.stateManagementService.token;
    if (!token) {
      this.navController.navigateRoot(Roots.auth + '/' + Roots.login);
      return false;
    }
    return true;
  }
}
