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 GuestGuard  {

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

  async canActivate(): Promise<boolean> {
    const token = await this.stateManagementService.token;
    if (token) {
      this.navController.navigateRoot(Roots.page);
      return false;
    }
    return true;
  }
}
