import { SignInfoVo } from './../../libs/tw/data/pet/SignInfoVo';
import { DataManager } from './../../libs/tw/manager/DataManager';
import { ModuleTypes } from './../types/sceneTypes';
import { NetManager } from "../../libs/tw/manager/NetManager";
import Panel from "../views/Panel";
import SceneCtrl from '../ctrls/sceneCtrl';

import { Buried } from "../../libs/tw/util/Buried";

export default class PunchCardSucPanel extends Panel {

    protected get skinKey() { return 'PunchCardSuc' }

    public bg: eui.Image;
    public closeBtn: eui.Button;
    public msgTitle: eui.Label;
    public msgTxt: eui.Label;
    public biggestGiftBg: eui.Image;
    public tips: eui.Label;
    public newToyTips: eui.Label;
    public giftName: eui.Label;
    public newToyBg: eui.Image;
    public giftbg: eui.Image;
    public newToy: eui.Image;
    public newGift: eui.Image;



    private scene: any;
    private unlockToy: string;
    private lottery: any;

    //埋点
    private exposures;
    private dayMark: string;

    start(data) {
        this.scene = data ? data.scene : null;
        this.unlockToy = data ? data.unlockToy : null;
        this.lottery = DataManager.ins.getPlugOrderStatusData ? DataManager.ins.getPlugOrderStatusData.lottery : null;
        setTimeout(() => {
            this.updateMsg();
        }, 20)

        this.initBuired();
    }

    updateMsg() {
        let signInfoVo = DataManager.ins.signInfoData.signInfoVO;
        //签到天数取余14
        var signDays = signInfoVo.acmDay ? signInfoVo.acmDay % 14 || 14 : 0;
        if (this.msgTxt && signDays) {
            if (signDays == 4 || signDays == 7) {
                //发送曝光埋点
                NetManager.ins.showLog(this.exposures["day47"]);
                this.dayMark = "day47"
                // 第4、7天文案及奖品展示
                this.msgTxt.text = `已打卡${signDays}天，恭喜解锁特殊奖励，\n累计打开14天更有惊喜礼包哦!`
                // 奖品   
                if (this.unlockToy) {
                    this.newToy.source = this.unlockToy;
                }
                if (!this.lottery) {
                    this.newGift.source = `heartBreak_png`;
                    this.giftName.text = `啊哦，奖品与你擦肩而过～`;
                    this.giftName.size = 20;
                }
                //有奖品时
                else {
                    this.newGift.source = this.lottery.img;
                    this.giftName.text = this.lottery.name;
                    //曝光埋点
                    if (this.lottery.imgExposure) NetManager.ins.showLog(this.lottery.imgExposure);
                }
            } else if (signDays >= 14) {
                //发送曝光埋点
                NetManager.ins.showLog(this.exposures["day14"]);
                this.dayMark = "day14";
                // 第14天文案及奖品展示
                if (window['currentPigData'] && window['currentPigData'].identifier == 'wastonA') {
                    this.msgTxt.text = `已打卡14天，恭喜已养成运动猪，\n明天即可开启新宠打卡哦！`
                } else if (window['currentPigData'] && window['currentPigData'].identifier == 'wastonB') {
                    this.msgTxt.text = `已打卡14天，恭喜已养成臭美猪，\n明天即可开启新宠打卡哦！`
                } else if (window['currentPigData'] && window['currentPigData'].identifier == 'wastonC') {
                    this.msgTxt.text = `已打卡14天，恭喜已养成社会猪，\n明天即可开启新宠打卡哦！`
                } else {
                    this.msgTxt.text = `已打卡14天，恭喜已养成宠物猪，\n明天即可开启新宠打卡哦！`
                }
                // 奖品  
                if (this.unlockToy) {
                    this.newToy.source = this.unlockToy;
                }
                if (!this.lottery) {
                    this.newGift.source = `heartBreak_png`;
                    this.giftName.text = `啊哦，奖品与你擦肩而过～`;
                    this.giftName.size = 20;
                }
                //有奖品时
                else {
                    this.newGift.source = this.lottery.img;
                    this.giftName.text = this.lottery.name;
                    //曝光埋点
                    if (this.lottery.imgExposure) NetManager.ins.showLog(this.lottery.imgExposure);
                }
            } else {
                if (signDays < 4) {
                    this.msgTxt.text = `已打卡${signDays}天，再坚持${4 - signDays}天可获得\n特殊奖励，继续加油!`
                } else if (signDays < 7) {
                    this.msgTxt.text = `已打卡${signDays}天，再坚持${7 - signDays}天可获得\n特殊奖励，继续加油!`
                } else if (signDays < 14) {
                    this.msgTxt.text = `已打卡${signDays}天，再坚持${14 - signDays}天可获得\n特殊奖励，继续加油!`
                }
                //发送曝光埋点
                NetManager.ins.showLog(this.exposures["usual"]);
                this.dayMark = "usual";
                // 奖品
                this.biggestGiftBg.visible = false;
                this.tips.y = 550;
                this.tips.size = 32;
                this.tips.text = `已解锁新道具！`;
                this.giftbg.visible = false;
                this.giftName.visible = false;
                this.newGift.visible = false;
                this.newToyTips.visible = false;
                this.newToyBg.source = `bigGiftBox_png`;
                this.newToyBg.anchorOffsetX = 131;
                this.newToyBg.anchorOffsetY = 131;
                this.newToyBg.x = 375
                this.newToyBg.y = 730;
                this.newToy.width = 200;
                this.newToy.height = 200;
                this.newToy.anchorOffsetX = 100;
                this.newToy.anchorOffsetY = 100;
                this.newToy.x = 375
                this.newToy.y = 730;
                if (this.unlockToy) {
                    this.newToy.source = this.unlockToy;
                }
            }
        }
    }

    initBuired() {
        this.exposures = {};
        var dpmUsual = Buried.connectDpm(40, 6, 1);
        var dpmDay47 = Buried.connectDpm(40, 6, 2);
        var dpmDay14 = Buried.connectDpm(40, 6, 3);
        var num;
        switch (window["currentPigData"].identifier) {
            case "wastonA":
                num = 1;
                break;
            case "wastonB":
                num = 2;
                break;
            case "wastonC":
                num = 3;
                break;
        }
        var dcm = Buried.connectDcm(230, window['skinID'], num);

        this.exposures["usual"] = Buried.createExposure(dpmUsual, dcm);
        this.exposures["day47"] = Buried.createExposure(dpmDay47, dcm);
        this.exposures["day14"] = Buried.createExposure(dpmDay14, dcm);

    }

    initEvents() {
        this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onTap_closeBtn, this);
    }

    private onTap_closeBtn() {
        this.hidePanel();
        //点击埋点
        NetManager.ins.clickLog(this.exposures[this.dayMark])

    }

}