import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree } from '@angular/router';
import { Observable } from 'rxjs';
import { SessionStore } from '../store/session.service';

@Injectable({
  providedIn: 'root'
})
export class InactivityGuard implements CanActivate {

  constructor(
    private router:Router
  ){}

  canActivate(
    route: ActivatedRouteSnapshot,
    state: RouterStateSnapshot): Observable<boolean | UrlTree> | Promise<boolean | UrlTree> | boolean | UrlTree {

      if(SessionStore.exist && SessionStore.user.Inactivity && !SessionStore.hasPin) {
        // alert('stay set pin')
        return true

      } else if(SessionStore.exist && !SessionStore.user.Inactivity) {
        // alert('stay conform')
        return true
      } else {
        this.router.navigate(['/home/events']);
        return false
      }
      
  }
  
}
