import showCustomLog from "../../libs/new_tw/ctrls/showCustomLog";
import Panel from "../../libs/new_wx/components/Panel";
import { LotteryType } from "../../libs/tw/enum/LotteryType";
import { DataManager } from "../../libs/tw/manager/DataManager";
import { NetManager } from "../../libs/tw/manager/NetManager";
import SceneCtrl from "../../libs/new_wx/ctrls/sceneCtrl";
import { ModuleTypes } from "../../libs/new_wx/types/sceneTypes";

export default class PrizePanel extends Panel {
    start(data) {
        const lottery = DataManager.ins.getCustomOrderStatusData.lottery;
        this.data = lottery;
        if (lottery) showCustomLog(lottery);
    }

    initEvents() {
        super.initEvents();
        if (this.useBtn) this.useBtn.once(egret.TouchEvent.TOUCH_TAP, this.onUse, this);
        if (this.img) this.img.once(egret.TouchEvent.TOUCH_TAP, this.onUse, this);
    }

    onUse() {
        const lottery = DataManager.ins.getCustomOrderStatusData.lottery;
        if (lottery.type == LotteryType.COUPON || lottery.type == LotteryType.LUCKY) {
            window["downloadAppConfig"] =
                {
                    openUrl: lottery.openUrl,
                    iosDownloadUrl: lottery.iosDownloadUrl,
                    androidDownloadUrl: lottery.androidDownloadUrl,
                    confirm: lottery.confirm ? lottery.confirm : false
                };
            window["downloadApp"]();
            if (lottery.type == "lucky") {
                NetManager.ins.spmclick(DataManager.ins.getCustomOrderStatusData.exposure);
            }
        }
        else {
            window.location.href = lottery.link;
        }
    }

    onTouchTap_closeBtn() {
        this.hidePanel();
        SceneCtrl.instance.change(ModuleTypes.START_SCENE);
    }

    get skinKey() { return 'Prize' }

    img: eui.Image;
    useBtn: eui.Button;
}