import Panel from "../views/Panel";
import { NetManager } from "../../libs/tw/manager/NetManager";
import PanelCtrl from "../ctrls/panelCtrl";
import { ModuleTypes } from "../types/sceneTypes";
import SceneCtrl from "../ctrls/sceneCtrl";
import { GFun } from "../../libs/tc/util/GFun";
import StartScene from "../startScene/StartScene";
import { GetBuriedData } from "../ctrls/GetBuriedData";

export default class NoPrizePanel extends Panel {
    public get skinKey() { return 'NoPrizePanel' }
    public get groupName() { return 'card' }

    public backBtn: eui.Button;
    public closeBtn: eui.Button;
    private mData: any;

    public clickBG:eui.Rect;
    private backExposure: any;
    constructor(data?) {
        super(data);
        this.mData = data;
        // this.startList.height = 1080/window.innerWidth*window.innerHeight;
    }

    initEvents() {
        super.initEvents();
        this.backBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.backPanel, this);
        this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closePanel, this);
        this.clickBG.addEventListener(egret.TouchEvent.TOUCH_TAP, this.closePanel, this);
    }

    removeEvents() {
        super.removeEvents();
        this.backBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.backPanel, this);
        this.closeBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.closePanel, this);
        this.clickBG.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.closePanel, this);
    }

    start() {
        super.start();
        this.percentHeight = 100;

    }
    private cityJson;
    protected async preLoadRes() {
        //加载背景并设置背景图片

        return new Promise(function (resolve, reject) {
            resolve();
        });

    }

    protected onSkinComplete(): void {
        super.onSkinComplete();
        this.once(egret.Event.ADDED_TO_STAGE, this.onLoad, this);
        if (this.stage) {
            this.onLoad();
        }
    }

    private onLoad(): void {
        this.initUI();
        this.initBuried()
    }

    initUI() {


    }
    initBuried() {
        this.backExposure = GetBuriedData(19)
        NetManager.ins.showLog(this.backExposure);
    }
    closePanel() {
        NetManager.ins.queryTaskList((success, result) => {
            if (!success) {
                PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: result.message })
            }
            NetManager.ins.getBaseInfo((success2, result2) => {
                if (!success2) {
                    PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: result2.message })
                }
                NetManager.ins.getSubscibeState((success3, result3) => {
                    if (!success3) {
                        PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: result2.message })
                    }
                    let data = { baseinfo: result2.data, taskinfo: result.data, pushstatus: result3.data.status };
                    // SceneCtrl.instance.change(ModuleTypes.START_SCENE,data);
                    StartScene.instance.mData = data;
                    StartScene.instance.initUI();
                    //StartScene.instance.startList.viewport.scrollV = StartScene.instance.diheight - 1080 / window.innerWidth * window.innerHeight
                    this.hidePanel();
                })

            })
        })
    }
    backPanel() {
        NetManager.ins.clickLog(this.backExposure);

        NetManager.ins.queryTaskList((success, result) => {
            if (!success) {
                PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: result.message })
            }


            NetManager.ins.getBaseInfo((success2, result2) => {
                if (!success2) {
                    PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: result2.message })
                }
                NetManager.ins.getSubscibeState((success3, result3) => {
                    if (!success3) {
                        PanelCtrl.instance.show(ModuleTypes.TOAST_PANEL, { msg: result2.message })
                    }
                    let data = { baseinfo: result2.data, taskinfo: result.data, pushstatus: result3.data.status };
                    // SceneCtrl.instance.change(ModuleTypes.START_SCENE,data);
                    StartScene.instance.mData = data;
                    StartScene.instance.initUI();
                    //StartScene.instance.startList.viewport.scrollV = StartScene.instance.diheight - 1080 / window.innerWidth * window.innerHeight
                    this.hidePanel();
                })

            })
        })
    }



}