import { Injectable, OnInit } from '@angular/core';
import { CanActivateChild, Router, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
// import { PermissionService } from './permission.service';
// import { MenuService } from './menu.service';

@Injectable()
export class AuthService implements CanActivateChild, OnInit {
    // public login = false;
    // private permissionR = '';

    constructor(private router: Router) {
    }

    ngOnInit() {
    }

    canActivateChild(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
        // const layoutCon = document.getElementById('layoutCon');
        // if (layoutCon) {
        //     layoutCon.scrollTop = 0;
        // }
        // return this.checkLogin() && this.permissionCheck(state.url);
        // // return this.checkLogin();
        return true;
    }

    // // 登录验证,如果有值就返回true.没有就跳转登录
    // checkLogin() {
    //     if (window.sessionStorage.getItem('_AMap_AMap.MapInner')) {
    //         return true;
    //     }
    //     this.router.navigate(['/extra/login']);
    //     return false;
    // }
    //
    // // 路由跳转权限检测
    // permissionCheck(routerUrl) {
    //     clearInterval(parseInt(window.sessionStorage.getItem('_inv'), 10));
    //     let routerReq;
    //     if (routerUrl.indexOf('?') > -1) {
    //         routerReq = routerUrl.slice(0, routerUrl.indexOf('?'));
    //     } else {
    //         routerReq = routerUrl;
    //     }
    //     routerReq = routerReq.split('/');
    //     if (routerReq[routerReq.length - 1] === 'xdkDetail' || routerReq[routerReq.length - 1] === 'cissDetail'
    //         || routerReq[routerReq.length - 1] === 'warnEdit' || routerReq[routerReq.length - 1] === 'warnNew') {
    //         this.permissionR = routerReq[routerReq.length - 2];
    //     } else {
    //         this.permissionR = routerReq[routerReq.length - 1];
    //     }
    //     const permissions = JSON.stringify(this.permission.getTiny());
    //     if (permissions.indexOf(this.permissionR) > -1) {
    //         return true;
    //     } else {
    //         return false;
    //     }
    // }
}
