
const DWTool = require('../utils/DWTool')
const GameModule = require('../utils/GameModule')
const WeChat = require('../net/WeChat');
cc.Class({
    extends: cc.Component,

    properties: {
        
        content: cc.Node,

        coinRichText: cc.RichText,
        
        watchVideoRichText: cc.RichText,
        
        shareRichText: cc.RichText,

        secretarySprite: cc.Node,

        grossIncome: {
            get: function() {
                if (this._grossIncome) {
                    this._grossIncome = 0;
                }
                return this._grossIncome;
            },

            set: function (value) {
                this._grossIncome = value;
                this.setCoinRichText(value);
                this.setWatchVideoRichText(value);
                this.setShareVideoRichText(value);
            }
        }
    },

    // LIFE-CYCLE CALLBACKS:

    init(grossIncome) {
        this.grossIncome = grossIncome;
    },

    onLoad () {

    },


    start () {
        this.content.scaleX = 0;
        this.content.scaleY = 0;
        this.content.runAction(cc.scaleTo(0.35, 1, 1).easing(cc.easeBackOut()));

        this.secretarySprite.runAction(cc.moveBy(0.3, cc.v2(400, 0)));
    },

    dismiss() {
        let finish = cc.callFunc(() => {
            this.node.destroy();
        }, this);
        let sequence = cc.sequence(cc.scaleTo(0.2, 0, 0).easing(cc.easeBackIn()), finish)
        this.content.runAction(sequence);
    },


    watchVideo() {
        this.dismiss();
    },

    share() {

        WeChat.inviteFriend(ShareAction.ADD_FRIEND, () => {
            GameModule.userInfo.grossIncome += this.grossIncome * 3;
            this.dismiss();
        }, () => {
            this.dismiss();
        });
    },

    setCoinRichText(coin) {
        this.coinRichText.string = `<img src='alert_coin'/><outline color=#ffffff width=4><b><color=#009227> ${DWTool.coinParse(coin)}</c></b></outline>`;
    },

    setWatchVideoRichText(coin) {
        this.watchVideoRichText.string = `<img src='alert_coin'/><color=#ffffff> ${DWTool.coinParse(coin * 2)}</c>`;
    },

    setShareVideoRichText(coin) {
        this.shareRichText.string = `<img src='alert_coin'/><color=#ffffff> ${DWTool.coinParse(coin * 3)}</c>`;
    },


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