var TalentApi = require('../net/TalentApi');
const wechat = require('../net/WeChat');

cc.Class({
    extends: cc.Component,

    properties: {

        contentNode: cc.Node,

        invitedPrefab: cc.Prefab,
        invitedScrollViewNode: cc.ScrollView,

        listScrollViewNode: cc.ScrollView,
        missionPrefab: cc.Prefab,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {

    },

    start () {

    },

    onDisable() {
        for (let child of this.invitedScrollViewNode.content.children) {
            child.destroy();
        }

        for (let child of this.listScrollViewNode.content.children) {
            child.destroy();
        }
    },

    // update (dt) {},
    init() {
        this.node.parent = cc.find('Canvas');
        this.node.active = true;

        this.contentNode.y = -cc.view.getVisibleSize().height;
        this.contentNode.runAction(cc.moveTo(0.2, 0, 0).easing(cc.easeCubicActionOut()));

        this.layout();
    },

    closeNode() {
        let finish = cc.callFunc(() => {
            this.node.active = false;
        }, this);
        this.contentNode.runAction(cc.sequence(cc.moveTo(0.2, 0, -cc.view.getVisibleSize().height).easing(cc.easeCubicActionIn()), finish));
    },

    layout() {
        for (var i = 0; i < 10; i++) {
            let item = cc.instantiate(this.invitedPrefab);
            item = item.getComponent('TalentInvitedItem');
            item.node.parent = this.invitedScrollViewNode.content;
        }

        for (var i = 0; i < 10; i++) {
            let item = cc.instantiate(this.missionPrefab);
            item = item.getComponent('TalentInviteMissionItem');
            item.node.parent = this.listScrollViewNode.content;
            item.node.width = this.listScrollViewNode.node._contentSize.width;
        }
    },

    inviteArtist() {
        wechat.inviteFriend(ShareAction.BECOME_ARTIST);
    },
});
