import { Injectable } from '@angular/core';
import { ActivatedRouteSnapshot, Router, RouterStateSnapshot } from '@angular/router';
import {INIT_FLAG, ROLE_TYPE} from './local-storage.namespace';
import {BrowserStorageService} from "../utils/localStorage.service";


@Injectable()
export class InitGuardService  {
  constructor(
    private storage: BrowserStorageService,
    private router: Router,
  ) { }

  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
    const init = !!this.storage.get(INIT_FLAG);
    const type = Number(this.storage.get(ROLE_TYPE));
/*    if (type === 1) {
      if (state.url.includes('login') && init) {
        this.router.navigateByUrl('/company/index').then();
        return false;
      }
      if (!state.url.includes('login') && !init) {
        this.router.navigateByUrl('/login').then();
        return false;
      }
    } else {
      if (state.url.includes('adminLogin') && init) {
        this.router.navigateByUrl('/admin/index').then();
        return false;
      }
      if (!state.url.includes('adminLogin') && !init) {
        this.router.navigateByUrl('/login').then();
        return false;
      }
    }*/
    return true;
  }
}
