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

@Injectable({
    providedIn: 'root'
})
export class SuperAdminAuthGuard implements CanActivate, CanActivateChild {

    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 == 'SuperAdmin')
                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;
    }

}
