import { Injectable } from '@angular/core';
import { CanActivate, Router } from '@angular/router';
import {LocalStorageService} from "angular-2-local-storage";

@Injectable()
export class CoachAuthenticationService implements CanActivate {
  constructor(protected localStorageService: LocalStorageService, private router: Router) {

    console.log(localStorage.getItem('testAuth'));
    console.log(this.localStorageService.get('testAuth'));
    // alert(this.localStorageService.get('userInfo'));
    //alert(localStorage.getItem('testAuth'));
  }
  canActivate(): boolean {

    let AuthSafe = this.localStorageService.get('userInfo');
    if (AuthSafe && AuthSafe['roles']) {
      if (new RegExp('COACH').test(AuthSafe['roles'])) {
        //  this.router.navigateByUrl('/comingSoon');
        return true;
      } else {
        this.router.navigateByUrl('/employee')
        return false;
      }
    } else {
      this.router.navigateByUrl('')
      return false;
    }
  }
}
