import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { routePath } from 'src/app/_providers/_resources/route-path.properties';

@Injectable({
  providedIn: 'root'
})
export class AnalystAuthGuard implements CanActivate {
  constructor(
    private router: Router,

) { }

async canActivate(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Promise<boolean> {
    const currentUser = localStorage.getItem("authtoken");
    const seculevel = localStorage.getItem("seculevel");

    if (currentUser) {
        if (seculevel == 'Analyst')
            return true;
        else
            return false;
    }
    await this.router.navigate([routePath.login], { queryParams: { returnUrl: state.url } });
    return false;
}

canActivateChild(
    next: ActivatedRouteSnapshot,
    state: RouterStateSnapshot,
): Observable<boolean> | Promise<boolean> | boolean {


    return true;
}
  
}
