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

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

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

    if(!SessionStore.user.Inactivity) {
      this.router.navigate(['/']);
      return false
    }
    else if(!SessionStore.exist) {
      this.router.navigate(['/']);
      return false
    } else {
      return true
    }
  }

}
