const StarApi = require('../net/StarApi');
const AlertManager = require('../utils/AlertManager');

cc.Class({
    extends: cc.Component,

    properties: {
        
        scrollView: cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.node.height = cc.view.getVisibleSize().height;
        this.scrollView.active = false;
    },

    start () {
        this.getSignStars().then((respondData) => {
            this.scrollView.active = true;
            this.scrollView.getComponent('StarScrollView').init(respondData);
        }).catch((code) => {
            cc.log(code);
        });

        GameEvent.on("starAlert_done", this, () => {
            this.node.destroy();
        });
    },

    onDestroy() {
        GameEvent.off("starAlert_done", this);
    },
    /// 网络请求
    getSignStars() {
        return new Promise((resolve, reject) => {
            StarApi.getSignStars((respondData) => {
                resolve(respondData);
            }, (code) => {
                reject(code);
            });
        })
    },
    update (dt) {},

    photoAction() {

    },

    //显示明星图鉴
    handleStarHandbook: _.debounce((event) => {
        AlertManager.showStarHandbookAlert();
    }, 1000, true),
});
