import { Data } from './../../libs/tw/data/Data';
import { NetManager } from '../../libs/tw/manager/NetManager';
import { DataManager } from '../../libs/tw/manager/DataManager';
import Scene from "../views/Scene";
import GameConst from '../GameConst';
import PanelCtrl from '../ctrls/panelCtrl';
import { ModuleTypes } from '../types/sceneTypes';
import SceneCtrl from '../ctrls/sceneCtrl';
import Panel from '../views/Panel';
import { Buried } from './../../libs/tw/util/Buried';
export default class PigThemeScene extends Scene {

    get skinKey() { return 'PigTheme' }

    public bg: eui.Image;
    public title: eui.Image;
    public choosePanel: eui.Image;
    public backBtn: eui.Button;
    public ydPigBtn: eui.Button;
    public cmPigBtn: eui.Button;
    public shPigBtn: eui.Button;


    private pigTheme: string; // 猪的主题种类 wastonA wastonB wastonC
    private userLevel: any; // 用户vip等级 1 2 3
    private scene: any;
    private isSwitch: boolean;

    //曝光
    private exposures;

    start(data?) {
        this.isSwitch = data ? data.isSwitch : false;

        this.initScene();
        this.initBuired()
    }

    initScene() {
        this.percentWidth = 100;
        this.percentHeight = 100;

        setTimeout(() => {
            this.backBtn.visible = this.isSwitch;
        }, 20);

        if (DataManager.ins.getData('getAllPetsInfo') && DataManager.ins.getData('getAllPetsInfo').data) {
            DataManager.ins.getData('getAllPetsInfo').data.forEach(pig => {
                switch (pig.identifier) {
                    case 'wastonA':
                        this.ydPigBtn.icon = `adoptedBtn_png`;
                        this.ydPigBtn.touchEnabled = false;
                        break;
                    case 'wastonB':
                        this.cmPigBtn.icon = `adoptedBtn_png`;
                        this.cmPigBtn.touchEnabled = false;
                        break;
                    case 'wastonC':
                        this.shPigBtn.icon = `adoptedBtn_png`;
                        this.shPigBtn.touchEnabled = false;
                        break;
                }
            });
        }

    }

    initBuired() {

        this.exposures = {};
        var dpm = Buried.connectDpm(40, 2, 1);
        var dcm1 = Buried.connectDcm(230, window['skinID'], 1);
        var dcm2 = Buried.connectDcm(230, window['skinID'], 2);
        var dcm3 = Buried.connectDcm(230, window['skinID'], 3);

        this.exposures["1"] = Buried.createExposure(dpm, dcm1);
        this.exposures["2"] = Buried.createExposure(dpm, dcm2);
        this.exposures["3"] = Buried.createExposure(dpm, dcm3);
        //发送曝光埋点
        NetManager.ins.showLog(this.exposures["1"]);
        NetManager.ins.showLog(this.exposures["2"]);
        NetManager.ins.showLog(this.exposures["3"]);
    }

    initEvents() {
        super.initEvents();
        this.ydPigBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_ydPigBtn, this);
        this.cmPigBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_cmPigBtn, this);
        this.shPigBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_shPigBtn, this);
        this.backBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_backBtn, this);
    }

    removeEvents() {
        super.removeEvents();
        this.ydPigBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_ydPigBtn, this);
        this.cmPigBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_cmPigBtn, this);
        this.shPigBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_shPigBtn, this);
        this.backBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_backBtn, this);
    }


    // 运动猪
    onTap_ydPigBtn() {
        //点击埋点
        NetManager.ins.clickLog(this.exposures["1"]);

        this.pigTheme = `wastonA`;
        let data = { pigTheme: this.pigTheme };
        SceneCtrl.instance.change(ModuleTypes.PIGVIPLEVEL_SCENE, data);
    }

    // 臭美猪
    onTap_cmPigBtn() {
        //点击埋点
        NetManager.ins.clickLog(this.exposures["2"]);

        this.pigTheme = `wastonB`;
        let data = { pigTheme: this.pigTheme };
        SceneCtrl.instance.change(ModuleTypes.PIGVIPLEVEL_SCENE, data);
    }

    // 社会猪
    onTap_shPigBtn() {
        //点击埋点
        NetManager.ins.clickLog(this.exposures["3"]);

        this.pigTheme = `wastonC`;
        let data = { pigTheme: this.pigTheme };
        SceneCtrl.instance.change(ModuleTypes.PIGVIPLEVEL_SCENE, data);
    }

    onTap_backBtn() {
        let data = { isBack: true }
        SceneCtrl.instance.change(ModuleTypes.PLAY_SCENE, data);
        // SceneCtrl.instance.change(ModuleTypes.CALENDAR_SCENE)
        // PanelCtrl.instance.show(ModuleTypes.PUNCHCARDSUC_PANEL);
        // PanelCtrl.instance.show(ModuleTypes.PUNCHCARDFAIL_PANEL);
    }
}