// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

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;
        //     }
        // },
        num: cc.Label,
        des: cc.Label,
        group: cc.Node,
        icon: cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start() {

    },

    updateUI(data) {
        this.num.string = data.id;
        this.des.string = data.des;
        this.checks(data.id)
        utils.loadHttpSpriteFrame(data.img, this.icon.getComponent(cc.Sprite));
    },
    checks(id) {
        switch (id) {
            case 1:
            case 2:
            case 3:
                this.setAll(this.group,id-1,true)
                break;
            default:
                this.setAll(this.group,0,false)
                break;
        }
    },
    setAll(parent,index,b){
        if (parent.active == b) {
            return
        }
        parent.active = b
        for (var i = 0; i <parent.children.length ; i++) {
            parent.children[i].active = false
        }
        parent.children[index].active = b
    }

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