import { getSkinPath } from "../utils";
import PanelCtrl from "../ctrls/panelCtrl";
import { ModuleTypes } from "../types/sceneTypes";
import { btnDelay } from "../comm/UtilsConst";

export default class Bar extends eui.Component {
    public back: eui.Image;
    public rule: eui.Image;
    public title: eui.Label;

    private data = null;

    constructor(data?) {
        super();
        this.skinName = getSkinPath('Component/Bar');
        this.data = data || null;

        this.initEvents();
        // this.title.text = '工行卡中心';
    }

    private initEvents() {
        this.back.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
        this.rule.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap, this);
    }

    /// TODO 定义详细的操作
    private onTap(e: egret.TouchEvent) {
        btnDelay(e.target);
        switch(e.target) {
            case this.rule: // 规则
                PanelCtrl.instance.show(ModuleTypes.RULE_PANEL);
                break;

            case this.back: // 返回
                window.history.back();
                break;
            default:
                break;
        }
    }
}