const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;

cc.Class({
    extends: cc.Component,

    properties: {
        //
        actGiftFrames: {
            tooltip: '奖品大图',
            default: [],
            type: [cc.SpriteFrame]
        },

        actGiftSprite: cc.Sprite,
        actGiftLabel: cc.Label,

        zIndex: {

            default: 0,

            notify(oldValue) {
                //减少无效赋值
                if (oldValue === this.zIndex) {
                    return;
                }
                this.node.zIndex = this.zIndex;
            }
        },
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {

        this.giftMap = ['coin', 'diamond', 'ticket'];

        this.node.zIndex = this.zIndex;

        // GameEvent.on(GameNotificationKey.ShowActGift, this, (type, showText) => {
        //     this.node.active = true;
        //     this.giftMap.forEach((value, index) => {
        //         if (type == value) {
        //         this.actGiftSprite.spriteFrame = this.actGiftFrames[index];
        //         if (showText) {
        //             this.actGiftLabel.node.active = true;
        //             this.actGiftLabel.string = showText;
        //         } else {
        //             this.actGiftLabel.node.active = false;
        //         }
        //         }
        //     })
        // });
        // this.node.active = false;
    },

    init(type, showText) {
        this.giftMap.forEach((value, index) => {
            if (type == value) {
                this.actGiftSprite.spriteFrame = this.actGiftFrames[index];
                if (showText) {
                    this.actGiftLabel.node.active = true;
                    this.actGiftLabel.string = showText;
                } else {
                    this.actGiftLabel.node.active = false;
                }
            }
        })
    },

    hideActGift() {
        this.node.destroy();
    },

    start () {

    },

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