import { DataManager } from './../../libs/tw/manager/DataManager';
import Scene from "../views/Scene";
import Ani from "./Ani";
import PanelCtrl from "../ctrls/panelCtrl";
import { ModuleTypes } from "../types/sceneTypes";
import GameConst from "../GameConst";
import SVGACtrl from '../ctrls/svgaCtrl';


export default class MainScene extends Scene {

    public get skinKey() { return "Main" }

    public bg: eui.Image;
    public diamondNum: eui.Component;
    public coinNum: eui.Component;
    public nickName: eui.Component;
    public payBtn: eui.Component;
    public addSpeedBtn: eui.Component;
    public barCounter: eui.Image;
    public refrigerator: eui.Image;
    public vase: eui.Image;
    public table0: eui.Image;
    public table1: eui.Image;
    public table2: eui.Image;
    public table3: eui.Image;
    public coffeeMakerGroup: eui.Group;
    public coffeeMaker: eui.Image;
    public decorateBtn: eui.Button;
    public redPacketBtn: eui.Button;
    public exchangeBtn: eui.Button;
    public taskBtn: eui.Button;
    public waitress: eui.Image;
    public ovenGroup: eui.Group;
    public oven: eui.Image;


    private mainConfig = {
        "username": "",
        "storeLevel": 0,
        "coin": 0,
        "diamond": 0
    }

    constructor(data?) {
        super();
        this.percentHeight = 100;
        this.percentWidth = 100;

        this.firstVisit = data;

        // 初始化UI
        this.initUI()
        // 初始化埋点
        this.initBuired();
        // 初始化动效
        this.initAni();

        this.initLogic();
    }


    initUI() {
        const { goldCoin, diamond, storeLevel, nickName, storeUpgrade, hasUpgradeReward, upgradeReward, tableLevel, tableCapacity, ovenLevel,
            ovenCapacity, freezerLevel, freezerCapacity, coffeeMakerLevel, coffeeMakerCapacity, checkstandLevel, checkstandCapacity,
            waiterLevel, waiterCapacity, chickenNewEnable, chickenEnable, chickenCould, chickenDuring, chickenEndTime, chickenRemainTime,
            feeNewEnbale, feeEnbale, feeNeedPay, feeNextPayTime, grabNewEnable, grabEnable, grabCould, grabNextTime } = DataManager.ins.getData("index").data;

        this.nickName['usernametxt'].text = nickName + "的咖啡屋"
        this.nickName['levelTxt'].text = "Lv" + storeLevel + ""
        this.coinNum['coinNumTxt'].text = GameConst.tranNumber(Number(goldCoin + ""), 1);
        this.diamondNum['diamondNumTxt'].text = GameConst.tranNumber(Number(diamond + ""), 1);

        if (Number(tableLevel) > 0) {
            for (let i = 0; i < 4; i++) {
                this['table' + i].visible = true;
                this['table' + i].scaleX = 1;
                this['table' + i].scaleY = 1;
                this['table' + i].source = `table10${tableLevel}_png`;
            }
        }

        if (Number(ovenLevel) > 0) {
            this.ovenGroup.visible = true;
            this.ovenGroup.scaleX = 1;
            this.ovenGroup.scaleY = 1;
            this.oven.source = `ovenLv${ovenLevel}_png`
        }

        if (Number(freezerLevel) > 0) {
            this.refrigerator.visible = true;
            this.refrigerator.scaleX = 1;
            this.refrigerator.scaleY = 1;
            this.refrigerator.source = `refrigeratorLv${freezerLevel}_png`
        }

        if (Number(coffeeMakerLevel) > 0) {
            this.coffeeMakerGroup.visible = true;
            this.coffeeMakerGroup.scaleX = 1;
            this.coffeeMakerGroup.scaleY = 1;
            this.coffeeMaker.source = `coffeeMakerLv${coffeeMakerLevel}_png`
        }

        if (Number(checkstandLevel) > 0) {
            this.barCounter.visible = true;
            this.barCounter.scaleX = 1;
            this.barCounter.scaleY = 1;
            this.barCounter.source = `barCounterLv${checkstandLevel}_png`
        }

        if (waiterLevel > 0) {
            for (let i = 0; i < 2; i++) {
                let waitress = new window['SVGA'].EgretMovieClip(SVGACtrl.instance.SVGAPool["waitressLv1"]);

                this.addChild(waitress)
            }
        }
    }

    updateMoney() {
        let goldCoin, diamond;
        this.coinNum['coinNumTxt'].text = GameConst.tranNumber(Number(goldCoin + ""), 1);
        this.diamondNum['diamondNumTxt'].text = GameConst.tranNumber(Number(diamond + ""), 1);
    }

    initAni() {

    }

    initBuired() {

    }

    firstVisit;
    initLogic() {
        // 是否首次进入
        const { sign } = DataManager.ins.getData("getTaskInfo").data;
        if (this.firstVisit) {
            // 首次访问 首次开店弹窗 然后新手引导
        } else {
            // 非首次访问
            // 是否签到
            if (sign) {
                // 今日已经签过到 无操作
            } else {
                // 今日未签到  进行签到
            }
        }
    }

    initEvents() {
        super.initEvents();
        this.onTap(this.taskBtn, this.onTap_taskBtn);
        this.onTap(this.decorateBtn, this.onTap_decorateBtn);
        this.onTap(this.exchangeBtn, this.onTap_exchangeBtn);
    }

    // 店长任务
    async onTap_taskBtn() {
        this.exchangeBtn.touchEnabled = false;
        let data = {}
        PanelCtrl.instance.slideUp(ModuleTypes.EXCHANGE_PANEL, GameConst.stage.stageHeight * 2 / 5, data);
        this.exchangeBtn.touchEnabled = true;
    }

    // 店铺装修
    async onTap_decorateBtn() {
        this.decorateBtn.touchEnabled = false;
        // await Ani.instance.createAni(this.table0);
        // await Ani.instance.awardCoinAni(this);
        let data = {}
        PanelCtrl.instance.slideUp(ModuleTypes.DECORATION_PANEL, GameConst.stage.stageHeight * 2 / 5, data)
        this.decorateBtn.touchEnabled = true
    }

    // 兑换好礼
    async onTap_exchangeBtn() {
        this.exchangeBtn.touchEnabled = false;
        let data = {}
        PanelCtrl.instance.slideUp(ModuleTypes.EXCHANGE_PANEL, GameConst.stage.stageHeight * 2 / 5, data);
        this.exchangeBtn.touchEnabled = true;
    }


    removeEvents() {
        super.removeEvents();
        this.clearTap(this.taskBtn, this.onTap_taskBtn);
        this.clearTap(this.decorateBtn, this.onTap_decorateBtn);
        this.clearTap(this.exchangeBtn, this.onTap_exchangeBtn);
    }




}