import questionSubmit from "../../libs/new_tw/ctrls/questionSubmit";
import Loading from "../../libs/new_wx/components/Loading";
import PanelCtrl from "../../libs/new_wx/ctrls/panelCtrl";
import SceneCtrl from "../../libs/new_wx/ctrls/sceneCtrl";
import { showToast } from "../../libs/new_wx/ctrls/toastCtrl";
import { ModuleTypes } from "../../libs/new_wx/types/sceneTypes";
import { DataManager } from "../../libs/tw/manager/DataManager";
import { SceneBase } from "../SceneBase";

export default class Result1Scene extends SceneBase {
    submitBtn: eui.Button;
    result;
    msg: eui.Label;
    againBtn: eui.Button;
    start(data) {
        super.start(data);
        this.result = data.result;
        this.submitBtn.once(egret.TouchEvent.TOUCH_TAP, this.onSubmit, this);
        this.againBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onAgain, this);
        this.msg.textFlow = (new egret.HtmlTextParser).parser('您答对了<font color=0xff0000 size=35 >' + data.rightSelectCounter + '</font>题!');
    }

    onAgain() {
        SceneCtrl.instance.change(ModuleTypes.START_SCENE);
    }

    onSubmit() {
        this.againBtn.touchEnabled=false;
        Loading.instace.show();
        questionSubmit((success) => {
            Loading.instace.hide();
            if (success) {
                if (DataManager.ins.getCustomOrderStatusData.lottery)
                    PanelCtrl.instance.show(ModuleTypes.PRIZE_PANEL)
                else {
                    showToast('对不起，您未中奖。');
                    SceneCtrl.instance.change(ModuleTypes.START_SCENE);
                }
            } else {
                SceneCtrl.instance.change(ModuleTypes.START_SCENE);
            }
        }, this.result);
    }

    get skinKey(): string { return 'Result1' }
    get skinResKey(): string { return 'result' }
}