var wechat = require('../net/WeChat');
cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        transparentBg: cc.Node,
        view: cc.Node,
        bg: cc.Node,
        titleLabel: cc.Label,
        closeNode: cc.Node,
        messageLabel: cc.Label,
        tipsLabel: cc.Label,
        button: cc.Node,
        buttonLabel: cc.Label,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad() {
        this.transparentBg.on(cc.Node.EventType.TOUCH_START, () => {
            this.dissmiss();
        }, this);

        this.bg.on(cc.Node.EventType.TOUCH_START, () => {

        }, this);

        this.closeNode.on(cc.Node.EventType.TOUCH_END, () => {
            this.dissmiss();
        }, this);

        this.button.on(cc.Node.EventType.TOUCH_END, () => {
            wechat.inviteFriend();
            // if (this.callback != undefined) {
            //     this.callback();
            // }
        }, this);
    },

    title(text) {
        this.titleLabel.string = text;
        return this;
    },

    message(text) {
        this.messageLabel.string = text;
        return this;
    },

    tips(text) {
        this.tipsLabel.string = text;
        return this;
    },

    buttonText(text) {
        this.buttonLabel.string = text;
        return this;
    },

    buttonCallback(callback) {
        this.callback = callback;
    },


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

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


    showXingtan() {
        this.titleLabel.string = '派出星探';
        this.messageLabel.string = '派出你的星探，为你免费寻找艺人。';
        this.tipsLabel.string = '发送星探链接给你的微信好友，\n让Ta免费成为你的艺人！'
        this.buttonLabel.string = '派出';
    },

    showInviteFriend() {
        this.titleLabel.string = '添加好友';
        this.messageLabel.string = '发送微信链接给你的微信好友即可添加为游戏好友。';
        this.tipsLabel.string = 'Tips：如果我的好朋友没有玩这款游戏呢？\n那你的星探就直接让Ta直接成为\n你的旗下艺人啦~'
        this.buttonLabel.string = '邀请';
    },
});
