import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
import { Observable, of } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { ConfigService } from '@shared/config/config.service';

@Injectable({
  providedIn: 'root'
})
export class ConfirmEmailResolver  {
  constructor(
    private config: ConfigService,
    private router: Router,
  ) {
  }

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): void {
    // redirect user to dashboard if his email is already confirmed
    if (this.config?.authService?.userData?.user?.email_verified) {
      this.router.navigateByUrl(this.config.getPanelHomeUrl()).then(() => {});
    }
  }
}
