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

/**
 * 滑动菜单菜单
 *
 * @export
 * @class AppSlideMenu
 */
@Component({
    selector: 'app-slide-menu',
    templateUrl: 'app-slide-menu.html',
    styleUrls: ['app-slide-menu.scss']
})
export class AppSlideMenu {
    /**
     * 菜单数据
     *
     * @type {any[]}
     * @memberof AppSlideMenu
     */
    @Input()
    set items(arr: any[]) {
        this.$items = [];
        if (arr && arr instanceof Array && arr.length > 0) {
            const num: number = Math.floor(arr.length / 8);
            const dataArr: any[] = [...arr];
            for (let i: number = 0; i <= num; i++) {
                this.$items.push({ items: dataArr.splice(0, 8)});
            }
        }
    }
    /**
     * 应用功能选择视图
     *
     * @type {string}
     * @memberof AppListMenu
     */
    @Input()
    appFuncPickupView: string;
    /**
     * 是否支持自定义
     *
     * @type {boolean}
     * @memberof AppListMenu
     */
    @Input()
    isCustom: boolean = false;
    /**
     * 菜单点击事件
     *
     * @type {EventEmitter<string>}
     * @memberof AppSlideMenu
     */
    @Output()
    menuClick: EventEmitter<string> = new EventEmitter();
    /**
     * 打开编辑视图
     *
     * @type {EventEmitter<string>}
     * @memberof AppListMenu
     */
    @Output()
    openPickup: EventEmitter<string> = new EventEmitter();

    /**
     * 菜单数据
     *
     * @type {any[]}
     * @memberof AppSlideMenu
     */
    public $items: any[] = [];

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

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

}