import {Component, OnInit} from '@angular/core';
import {Router} from '@angular/router';
import {Http} from '@angular/http';
import {LayoutService} from '../layout.service';
import {LocalStorageService, SessionStorageService} from 'ngx-webstorage';
import {ToTree} from '../../shared/common/toTree';


@Component({
    selector: 'jhi-sidebar',
    templateUrl: './sidebar.component.html',
    styles: [
            ` span i {
            margin-right: 10px;
        } `
    ]
})
export class SidebarComponent implements OnInit {
    token: boolean;

    constructor(public router: Router, private http: Http,
                public layoutSer: LayoutService,
                public toTreeSer: ToTree,
                private $localStorage: LocalStorageService,
                private $sessionStorage: SessionStorageService) {
    }

    menuList = [];

    ngOnInit() {
        this.getMenu();
    }

    getMenu() {
        this.layoutSer.getMenu().subscribe(
            (res) => {
                if (res.errCode == 10000) {
                    this.menuList = this.toTreeSer.listToTree('id', 'parentId', res.data);
                }
            }
        );
    }

    //简单使用

    openHandler(value: string): void {
        for (let key in this.menuList) {
            if (key !== value) {
                this.menuList[key].checked = false;
            }
        }
    }

    goTo(route) {
        this.router.navigate([route]);
    }
}
