import Loading from "../../libs/new_wx/components/Loading";
import PanelCtrl from "../../libs/new_wx/ctrls/panelCtrl";
import { ModuleTypes } from "../../libs/new_wx/types/sceneTypes";
import { NetManager } from "../../libs/tw/manager/NetManager";
import { TwFun } from "../../libs/tw/util/TwFun";
import { SceneBase } from "../SceneBase";
import SceneCtrl from "../../libs/new_wx/ctrls/sceneCtrl";

export default class StartScene extends SceneBase {
    ruleBtn: eui.Button;
    htmlRuleBtn: eui.Button;
    recordBtn: eui.Button;
    elements: eui.Group;

    exemptionTxt: eui.Label;

    onStart() {
        Loading.instace.show();
        NetManager.ins.doJoin((success) => {
            Loading.instace.hide();
            if (success) {
                SceneCtrl.instance.change(ModuleTypes.QUESTION_SCENE);
            }
        });
    }

    initEvents() {
        if (this.ruleBtn)
            this.ruleBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_ruleBtn, this);
        if (this.htmlRuleBtn)
            this.htmlRuleBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_htmlRuleBtn, this);
        if (this.recordBtn)
            this.recordBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_recordBtn, this);
        this['link'].once(egret.TouchEvent.TOUCH_TAP, this.onTap_linkBtn, this);
        this['startBtn'].addEventListener(egret.TouchEvent.TOUCH_TAP, this.onStart, this);
    }

    onTap_linkBtn() {
        window.location.href = window['link'];
    }

    onTap_ruleBtn(e: egret.Event) {
        PanelCtrl.instance.show(ModuleTypes.RULE_PANEL);
    }
    onTap_htmlRuleBtn(e: egret.Event) {
        PanelCtrl.instance.show(ModuleTypes.HTML_RULE_PANEL);
    }

    onTap_recordBtn(e: egret.Event) {
        window.location.href = TwFun.getRecordUrl('00');
    }

    get skinKey() { return 'Start' }
}