import { Component, Input, Output, EventEmitter } from '@angular/core';

/**
 * 宫格菜单
 *
 * @export
 * @class AppPalaceMenu
 */
@Component({
    selector: 'app-palace-menu',
    templateUrl: 'app-palace-menu.html',
    styleUrls: ['app-palace-menu.scss']
})
export class AppPalaceMenu {
    /**
     * 菜单数据
     *
     * @type {any[]}
     * @memberof AppPalaceMenu
     */
    @Input()
    items: any[] = [];
    /**
     * 应用功能选择视图
     *
     * @type {string}
     * @memberof AppListMenu
     */
    @Input()
    appFuncPickupView: string;
    /**
     * 是否支持自定义
     *
     * @type {boolean}
     * @memberof AppListMenu
     */
    @Input()
    isCustom: boolean = false;
    /**
     * 菜单点击事件
     *
     * @type {EventEmitter<string>}
     * @memberof AppPalaceMenu
     */
    @Output()
    menuClick: EventEmitter<string> = new EventEmitter();
    /**
     * 打开编辑视图
     *
     * @type {EventEmitter<string>}
     * @memberof AppListMenu
     */
    @Output()
    openPickup: EventEmitter<string> = new EventEmitter();

    /**
     * 菜单点击
     *
     * @param {string} appFuncId
     * @memberof AppPalaceMenu
     */
    public onClick(item: any): void {
        this.menuClick.emit(item);
    }

    /**
     * 展开状态改变
     *
     * @memberof AppPalaceMenu
     */
    public openChange(item: any): void {
        if (item.isOpen === true) {
            item.isOpen = false;
        } else {
            item.isOpen = true;
        }
    }

    /**
     * 编辑菜单项
     *
     * @memberof AppListMenu
     */
    public editMenus(): void {
        this.openPickup.emit(this.appFuncPickupView);
    }

}