var {UserInformationType, UserInformationRelateOptType, GameNotificationKey, UserIntimacyType} = require('../utils/GameEnum');

cc.Class({
    extends: cc.Component,

    properties: {

        titleNode: cc.Node,
        titleRichText: cc.RichText,

        homeButton: cc.Button,

        //抢夺、赎身相关操作按钮
        relationButtonNode: cc.Node,
        relationRichText: cc.RichText,
        //安抚按钮
        interactionButtonNode: cc.Node,
        //命令、反抗按钮
        orderButtonNode: cc.Node,
        //培养按钮
        trainButtonNode: cc.Node,

        //抢夺、赎身、签约成功提示
        successNode: cc.Node,
        successTipsNode: cc.Node,

        //背包按钮节点
        packButtonNode: cc.Node,

        //亲密度显示
        intimacyNode: cc.Node,
        intimacyFullNode: cc.Node,
        intimacyLeftNode: cc.Node,
        intimacyRightNode: cc.Node,
        intimacyLabel: cc.Label,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.titleSprite = this.titleNode.getComponent(cc.Sprite);

        this.successNode.on('touchstart',this.clossSuccessNode,this);

        this.intimacyNode.on('touchend', this.showIntimacyStatus, this);
    },

    start () {

    },

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

    onDisable() {
        this.relationButtonNode.active = false;
        this.interactionButtonNode.active = false;
        this.orderButtonNode.active = false;
        this.homeButton.node.active = false;
        this.successNode.active = false;
        this.successTipsNode.active = false;
        this.packButtonNode.active = false;

        this.intimacyNode.active = false;
    },

    // update (dt) {},

    changeTheme(infoTheme) {
        this.infoTheme = infoTheme;

        switch (this.infoTheme) {
            case UserInformationType.Mine:
                this.refreshThemeOfMine();
                break;
            case UserInformationType.Boss:
                this.refreshThemeOfBoss();
                break;
            case UserInformationType.MyArtist:
                this.refreshThemeOfMyArtist();
                break;
            case UserInformationType.OtherArtist:
                this.refreshThemeOfOtherArtist();
                break;
            case UserInformationType.ArtistFree:
                this.refreshThemeOfArtistFree();
                break;
        }
    },

    refreshThemeOfMine () {
        this.titleRichText.string = "<outline color=#690802 width=3><b>我的信息</b></outline>";

        this.intimacyNode.active = false;

        this.homeButton.node.active = false;

        this.relationButtonNode.active = false;
        this.interactionButtonNode.active = false;
        this.orderButtonNode.active = false;
        this.trainButtonNode.active = false;
        this.packButtonNode.active = true;
    },

    refreshThemeOfBoss () {
        this.titleRichText.string = "<outline color=#690802 width=3><b>我的老板</b></outline>";

        this.relationRichText.string = "<outline color=#2a7019 width=2><b>赎身</b></outline>";

        cc.loader.loadRes('userInformation/userinformation_play_button', cc.SpriteFrame, (err, spriteFrame) => {
            this.interactionButtonNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        });

        cc.loader.loadRes('userInformation/userinformation_revolt_button', cc.SpriteFrame, (err, spriteFrame) => {
            this.orderButtonNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        });

        this.intimacyNode.active = true;

        this.homeButton.node.active = true;
        
        this.relationButtonNode.active = true;
        this.interactionButtonNode.active = true;
        this.orderButtonNode.active = true;
        this.trainButtonNode.active = false;
        this.packButtonNode.active = false;
    },

    refreshThemeOfMyArtist () {
        this.titleRichText.string = "<outline color=#690802 width=3><b>我的艺人</b></outline>";

        this.relationRichText.string = "<outline color=#2a7019 width=2><b>解雇</b></outline>";

        cc.loader.loadRes('userInformation/userinformation_pacify_button', cc.SpriteFrame, (err, spriteFrame) => {
            this.interactionButtonNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        });

        cc.loader.loadRes('userInformation/userinformation_order_button', cc.SpriteFrame, (err, spriteFrame) => {
            this.orderButtonNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        });

        this.intimacyNode.active = true;

        this.homeButton.node.active = true;

        this.relationButtonNode.active = false;
        this.interactionButtonNode.active = true;
        this.orderButtonNode.active = true;
        this.trainButtonNode.active = true;
        this.packButtonNode.active = false;
    },

    refreshThemeOfOtherArtist () {
        this.titleRichText.string = "<outline color=#690802 width=3><b>他人艺人</b></outline>";

        this.relationRichText.string = "<outline color=#2a7019 width=2><b>抢夺</b></outline>";

        cc.loader.loadRes('userInformation/userinformation_interact_button', cc.SpriteFrame, (err, spriteFrame) => {
            this.interactionButtonNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        });

        this.intimacyNode.active = true;

        this.homeButton.node.active = true;

        this.relationButtonNode.active = true;
        this.interactionButtonNode.active = true;
        this.orderButtonNode.active = false;
        this.trainButtonNode.active = false;
        this.packButtonNode.active = false;
    },

    refreshThemeOfArtistFree () {
        this.titleRichText.string = "<outline color=#690802 width=3><b>自由身</b></outline>";

        this.relationRichText.string = "<outline color=#2a7019 width=2><b>签约</b></outline>";

        cc.loader.loadRes('userInformation/userinformation_interact_button', cc.SpriteFrame, (err, spriteFrame) => {
            this.interactionButtonNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
        });

        this.intimacyNode.active = true;

        this.homeButton.node.active = true;

        this.relationButtonNode.active = true;
        this.interactionButtonNode.active = true;
        this.orderButtonNode.active = false;
        this.trainButtonNode.active = false;
        this.packButtonNode.active = false;
    },

    hideAllIntimacyNode() {
        this.intimacyFullNode.active = false;
        this.intimacyLeftNode.active = false;
        this.intimacyRightNode.active = false;
    },

    configIntimacyData(interactionInfo) {

        this.hideAllIntimacyNode();

        switch (interactionInfo.heart) {
            case UserIntimacyType.Empty:
                break;
            case UserIntimacyType.Full:
                this.intimacyFullNode.active = true;
                break;
            case UserIntimacyType.Left:
                this.intimacyLeftNode.active = true;
                break;
            case UserIntimacyType.Right:
                this.intimacyRightNode.active = true;
                break;
        }
        this.intimacyLabel.string = "亲密度："+ interactionInfo.intimacy +"/100";
    },

    clossSuccessNode() {
        this.successNode.active = false;
    },

    showChangeRelationSuccess(spriteFrameString) {
        this.successNode.active = true;
        Global.GameEvent.fire(GameNotificationKey.PlaySuccessAnimation); 

        cc.loader.loadRes(spriteFrameString, cc.SpriteFrame, (err, spriteFrame) => {
            this.successTipsNode.getComponent(cc.Sprite).spriteFrame = spriteFrame;
            this.successTipsNode.active = true;
        });
    },

    showIntimacyStatus() {
        Global.GameEvent.fire(GameNotificationKey.ShowInteraction);
    }
});
