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

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

  canActivate(): boolean {
    // Implement your logic to decide whether to redirect or not.
    // For example, you can check if a certain condition is met.
    // const shouldRedirect = false
    let shouldRedirect = localStorage.getItem('graud')
    if (shouldRedirect == '1') {
      console.log('shouldRedirect','In')
      // Redirect to the desired route upon browser refresh
      this.router.navigate(['/pages/order']);
      return false; // Prevent navigation to the original route
    }
    console.log('shouldRedirect','out')
    return true; // Allow navigation to the original route

  //   console.log('canActivate')
  //   // Add your logic here to determine if a refresh should redirect to another page
  //   let dd = localStorage.getItem('gruad')
  //   if(dd == '1'){
  //     console.log('dd') 
  //       console.log('shouldRedirect')
  //       this.router.navigate(['../']); // Redirect to the desired page
  //       return false;      
  //   } 
  //   return true;
  }
  
}
