import {Component, ElementRef, OnInit, ViewChild} from '@angular/core';
import { Router, ActivatedRouteSnapshot, NavigationEnd } from '@angular/router';
import { EmitService } from "../../shared/event/eventEmitter";
import { Title } from '@angular/platform-browser';
import {LocalStorageService, SessionStorageService} from "ngx-webstorage";
import { zh_CN,NzI18nService } from "ng-zorro-antd";
import {CommonService} from '../../shared/common/common.service';

@Component({
    selector: 'jhi-main',
    templateUrl: './main.component.html',
    styles:[`
    .container{
        margin: 0 16px;
        background-color: #fff;
    }
    `]
})
export class JhiMainComponent implements OnInit {
    @ViewChild('container') container:ElementRef;

    token: boolean;
    isCollapsed: boolean;
    constructor(
        private titleService: Title,
        private router: Router,
        private $localStorage: LocalStorageService,
        private $sessionStorage: SessionStorageService,
        public emitService: EmitService,
        private nzI18nService:NzI18nService,
        private commonSer:CommonService
    ) {}

    private getPageTitle(routeSnapshot: ActivatedRouteSnapshot) {
        let title: string = (routeSnapshot.data && routeSnapshot.data['pageTitle']) ? routeSnapshot.data['pageTitle'] : '智能监控';
        if (routeSnapshot.firstChild) {
            title = this.getPageTitle(routeSnapshot.firstChild) || title;
        }
        return title;
    }

    ngOnInit() {

        this.nzI18nService.setLocale(zh_CN);

        const accessToken = this.$localStorage.retrieve('accessToken');
        if(accessToken){
            this.token = true;
        }else{
            this.token = false;
        }

        this.router.events.subscribe((event) => {
            if (event instanceof NavigationEnd) {
                this.titleService.setTitle(this.getPageTitle(this.router.routerState.snapshot.root));
            }
        });
    }

    fullScreen(){
        this.commonSer.showInFullScreen(this.container.nativeElement,"RequestFullScreen")
    }
}
