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

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

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

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

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