cc.Class({
    extends: cc.Component,
    name: "KindGroup",
    properties: {
        template_node:{
            default:null,
            type: cc.Node,
        },

        layout:{
            default:null,
            type: cc.Layout
        }
    },

    init(data){
        this.node.removeAllChildren();
        let item, kind, len = data.length;
        this._num = len;
        for(let i = 0; i < len; i++){
            item = cc.instantiate(this.template_node);
            item.y = 0;
            this.node.addChild(item);
            kind = item.getComponent(cc.js.getClassByName('WordKind'));
            kind.init(data[i]);
            item.y += 80;
        }

        this.updateView();
    },

    updateView(){
        let sw = this.node.width;
        let wr = sw/1280;
        let num = this.node.childrenCount;
        let width = -1;
        let w_scale = 1;
        if (num== 1){
            this.layout.paddingLeft = 100;
            this.layout.spacingX = 100;
            width = 479;
        }
        else if (num== 2){
            this.layout.paddingLeft = 100;
            this.layout.spacingX = 100;
            width = 479;
        }
        else if (num== 3){
            this.layout.paddingLeft = 45;
            this.layout.spacingX = 45;
            width = 368;
        }
        else if (num== 4){
            this.layout.paddingLeft = 45;
            this.layout.spacingX = 30;
            width = 273;
        }
        else {
            this.layout.paddingLeft = 10;
            this.layout.spacingX = 10;
            width = (1280-num*10-10) / num;
            w_scale = width/273;
            w_scale *= 0.8;
        }

        this.layout.paddingLeft *= wr;
        this.layout.spacingX *= wr;
        width = width * wr;

        // width = Math.max(100, width);
        // width = Math.min(479, width);


        for(let i = 0; i < num; i++){
            this.node.children[i].width = width;
            this.node.children[i].getComponent(cc.js.getClassByName('WordKind')).updateScale(w_scale);
        }

    }
});