var cityList = require('../data/city');
const GameNotificationKey = require('../utils/GameEnum').GameNotificationKey;
const CityApi = require('../net/CityMapApi');
cc.Class({
    extends: cc.Component,

    properties: {
        shining: cc.Node,
        nextButton: cc.Node,
        nextText: cc.RichText,
    },

    onLoad() {
        this.shining.setScale(0);

        let self = this;
        let finish = cc.callFunc(() => {
            self.shining.runAction(cc.rotateBy(0.8, 100, 100).repeatForever());
        }, this);
        let scale = cc.sequence(cc.spawn(cc.scaleTo(0.4, 1, 1).easing(cc.easeBackIn()), cc.rotateBy(0.4, 100, 100)), finish);
        this.shining.runAction(scale);

        let nextCityId = Global.cityId + 1;
        if (nextCityId <= cityList.length) {
            this.nextText.string = '<outline color=#1d8610><b>开办新的分公司</b></outline>\n<color=#1d8610><b>下一个城市</b></color>';
        } else {
            this.nextText.string = '<outline color=#1d8610><b>恭喜你完成了所有公司的开发</b>\n</outline><color=#1d8610><b>敬请期待</b></color>';
        }
    },

    start() {

    },

    close() {

    },

    nextCity() {
        let nextCityId = Global.cityId + 1;
        if (nextCityId <= cityList.length) {
            Global.cityId = nextCityId;
            CityApi.openNewCity(
                (response) => {
                    GameEvent.fire(GameNotificationKey.ShowCityMap, this, true);
                },
                (code, msg) => {
                    console.log(msg);
                });
        }
        this.node.destroy();
    }

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