const HomeApi = require("../net/HomeApi");
const AlertManager = require('../utils/AlertManager');
const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;

cc.Class({
    extends: cc.Component,

    properties: {
        levelHomePrefab: cc.Prefab,

        myInfoTop: cc.Node,

        sidebar: cc.Node,

        clickAddMoney: cc.Prefab,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {

        // 创建一个事件监听实例, 用来实现跨节点监听事件
        GameEvent.init();

        // Global.user = {
        //     uid: 6000027,
        //     token: "d9687ba4-66b4-48b1-a7b8-7b417d26f6d7"
        // };
        // Global.user = {
        //     uid: 6000025,
        //     token: "6d4a4c0f-89a6-4c04-ab0f-6ad72f9e6a24"
        // };
        cc.debug.setDisplayStats(false);

        //我的家园
        let levelHome = cc.instantiate(this.levelHomePrefab);
        levelHome = levelHome.getComponent('LevelHome');
        levelHome.init(Global.user.uid);
        this.levelHome = levelHome;
        this.levelHome.node.active = true;

        this._showSidebarUI();

        let XHeight = 1624;
        this.winSize = cc.view.getVisibleSize();
        if (this.winSize.height >= XHeight) {
            this.myInfoTop.height = 180;
        }
    },

    start () {

    },

    _showSidebarUI() {
        let action = cc.moveBy(0.3, cc.v2(-this.sidebar.width, 0));
        this.sidebar.runAction(action);
    },

    //
    handleQuestPopup: _.debounce((event) => {
        AlertManager.showQuestPopup();
        event.target.getChildByName("notice_point").active = false;
    }, 1000, true),

    //显示抽奖界面
    handleShowDraw: _.debounce((event) => {
        AlertManager.showDrawAlert();
    }, 1000, true),

    // update (dt) {},
});
