import {Component, OnInit} from '@angular/core';
import {RequestService} from '../common/request.service';
import {LocalStorageService} from 'ngx-webstorage';
import {ActivatedRoute, Params, Router} from '@angular/router';
import {AppService} from '../../app.service';

declare let md5;

@Component({
    selector: 'smart-check-auth',
    templateUrl: './check-auth.component.html',
    styles: []
})
export class CheckAuthComponent implements OnInit {

    constructor(
        private reqSer: RequestService,
        private router: Router,
        private appSer: AppService,
        private activedRoute: ActivatedRoute,
        private $localStorage: LocalStorageService,
    ) {
    }

    ngOnInit() {
        this.activedRoute.queryParams.subscribe((params: Params) => {
            if (params.token) {
                this.$localStorage.store('accessToken', params.token);
            }
            if (params.type) {
                this.appSer.setOtherSystem(params.type);
                this.router.navigate([`${params.type}`]);
            } else {
                this.router.navigate(['app/main/home']);
            }
        });
    }

}
