
const { ccclass, property } = cc._decorator;
import { OpenActionType, PanelType } from '../../mk/system/UISystem';
/**
 * 打开指定名字的面板
 * @author 薛鸿潇
 */
@ccclass
export default class BtnOpenPanel extends cc.Component {

    @property({ displayName: '界面名字', tooltip: '对应路径：resources/prefab/uiPanel/' })
    private panel_name = '';
    @property({ displayName: '打开类型', tooltip: 'normal不操作，closeOther关闭其他，closeLast关闭上一个', type: cc.Enum(OpenActionType) })
    private open_type = OpenActionType.normal;
    @property({ displayName: '面板类型', tooltip: 'game游戏界面，module模块界面', type: cc.Enum(PanelType) })
    private panel_type = PanelType.module;
    @property({ displayName: '完成回调', tooltip: "面板打开完成后触发", type: cc.Component.EventHandler })
    public onComplete: cc.Component.EventHandler[] = [];

    onLoad() {
        if (!this.node.getComponent(cc.Button)) this.node.addComponent(cc.Button);
    }

    start() {
        this.node.on('click', this.openPanel, this);
    }

    private async openPanel() {
        await mk.ui.openPanel(this.panel_name, this.panel_type, this.open_type);
        const c_count = this.onComplete.length;
        for (let i = 0; i < c_count; i++) {
            if (this.onComplete[i].handler) this.onComplete[i].emit([])
        }
    }
    // update (dt) {}
}
