import { Component, OnInit, ChangeDetectionStrategy, Output, EventEmitter } from '@angular/core';
import { OBJECT } from 'src/app/core/enum/role';
import { AppTokenService } from 'src/app/core/service/security/app-token.service';

@Component({
    selector: 'app-menu',
    templateUrl: './menu.component.html',
    styleUrls: ['./menu.component.scss'],
    changeDetection: ChangeDetectionStrategy.OnPush
})
export class MenuComponent implements OnInit {
    @Output() onToggleMenu = new EventEmitter<boolean>()
    isExpandMenu: boolean = true
    role = []
    roleConfig = OBJECT
    constructor(
        private appTokenSV: AppTokenService
    ) { }

    ngOnInit(): void {
        this.handleResize()
        this.role = this.appTokenSV.user.rights
    }


    handleResize() {
        const current = window.innerWidth
        if(current < 1024){
            this.isExpandMenu = false
            this.onToggleMenu.emit(this.isExpandMenu)
        }
        const match = window.matchMedia('(min-width: 1024px)');
        match.addEventListener('change', (e) => {
            this.isExpandMenu = e.matches;
            this.onToggleMenu.emit(this.isExpandMenu)
        });
    }

    toggleMenu(){
        this.isExpandMenu = !this.isExpandMenu
        this.onToggleMenu.emit(this.isExpandMenu)
    }

}
