/**
 * @file ColGroup component
 * @author liangxiaojun(liangxiaojun@derbysoft.com)
 */

import React, {Component} from 'react';
import PropTypes from 'prop-types';

import SelectMode from '../_statics/SelectMode';
import SelectAllMode from '../_statics/SelectAllMode';
import SortingType from '../_statics/SortingType';

import Util from '../_vendors/Util';
import HorizontalAlign from '../_statics/HorizontalAlign';

class ColGroup extends Component {

    static SelectMode = SelectMode;
    static SelectAllMode = SelectAllMode;
    static SortingType = SortingType;

    constructor(props, ...restArgs) {
        super(props, ...restArgs);
    }

    render() {

        const {columns} = this.props;

        return columns ?
            <colgroup>
                {
                    columns.map((column, index) => column ?
                        <col key={index}
                             style={{
                                 width: column.width || 100,
                                 minWidth: column.minWidth || 100
                             }}/>
                        :
                        null
                    )
                }
            </colgroup>
            :
            null;

    }
}

ColGroup.propTypes = {

    /**
     * Children passed into table header.
     */
    columns: PropTypes.arrayOf(PropTypes.shape({

        /**
         * width of column
         */
        width: PropTypes.number,

        /**
         * minimum width of column
         */
        minWidth: PropTypes.number,

        /**
         * The class name of header.
         */
        headClassName: PropTypes.string,

        /**
         * Override the styles of header.
         */
        headStyle: PropTypes.object,

        /**
         * align of table header cell
         */
        headAlign: PropTypes.oneOf(Util.enumerateValue(HorizontalAlign)),

        /**
         * The render content in header.
         * (1) string，example： 'id'
         * (2) callback，example：function (colIndex) {return colIndex;}
         */
        headRenderer: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),

        /**
         * The class name of td.
         */
        bodyClassName: PropTypes.string,

        /**
         * Override the styles of td.
         */
        bodyStyle: PropTypes.object,

        /**
         * The render content in table.
         * (1) data key，example： 'id'
         * (2) data key tamplate，example：'${id} - ${name}'
         * (3) callback，example：function (rowData, rowIndex, colIndex) {return rowData.id;}
         */
        bodyRenderer: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),

        /**
         * align of table body cell
         */
        bodyAlign: PropTypes.oneOf(Util.enumerateValue(HorizontalAlign)),

        /**
         * The class name of footer.
         */
        footClassName: PropTypes.string,

        /**
         * Override the styles of footer.
         */
        footStyle: PropTypes.object,

        /**
         * The render content in footer.
         * (1) string，example： 'id'
         * (2) callback，example：function (colIndex) {return colIndex;}
         */
        footRenderer: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),

        /**
         * align of table footer cell
         */
        footAlign: PropTypes.oneOf(Util.enumerateValue(HorizontalAlign)),

        /**
         * If true,this column can be sorted.
         */
        sortable: PropTypes.bool,

        /**
         * Sorting property.
         */
        sortingProp: PropTypes.string,

        defaultSortingType: PropTypes.oneOf(Util.enumerateValue(SortingType)),

        span: PropTypes.func

    })).isRequired,

};

export default ColGroup;

@@ -1751,145 +1751,8 @@
 t,%0A%0A
-        /**%0A         * align of table header cell%0A         */%0A        headAlign: PropTypes.oneOf(Util.enumerateValue(HorizontalAlign)),%0A%0A
     
@@ -1991,32 +1991,308 @@
 pTypes.func%5D),%0A%0A
+        /**%0A         * align of table header cell%0A         */%0A        headAlign: PropTypes.oneOf(Util.enumerateValue(HorizontalAlign)),%0A%0A        /**%0A         * column span of table header%0A         */%0A        headSpan: PropTypes.oneOfType(%5BPropTypes.number, PropTypes.func%5D),%0A%0A
         /**%0A    
@@ -2934,32 +2934,169 @@
 zontalAlign)),%0A%0A
+        /**%0A         * column span of table body%0A         */%0A        bodySpan: PropTypes.oneOfType(%5BPropTypes.number, PropTypes.func%5D),%0A%0A
         /**%0A    
@@ -3667,32 +3667,169 @@
 zontalAlign)),%0A%0A
+        /**%0A         * column span of table foot%0A         */%0A        footSpan: PropTypes.oneOfType(%5BPropTypes.number, PropTypes.func%5D),%0A%0A
         /**%0A    
@@ -4091,39 +4091,8 @@
 pe))
-,%0A%0A        span: PropTypes.func
 %0A%0A  
@@ -4107,17 +4107,16 @@
 Required
-,
 %0A%0A%7D;%0A%0Aex

update ColGroup