import React, { Component, PropTypes } from 'react';
import { columnsConfig as columnsConfigPropType, globalConfig as globalConfigPropType } from './proptypes';

const GridBody = ({config, objects, idColumn, columns, columnKeys, children})=>{
    const {row: Row, cell: Cell, cellRendererBase: CellRenderer} = config;
    const rows = objects.map((current) => {
        const cells = columnKeys.map((key) => {
            let configForColumn = columns[key];
            let value = current[key];
            let content = configForColumn && configForColumn.content ? configForColumn.content : undefined;
            const args = {columns:columns, columnName:key, config:config, value:value, object:current};
            if (content && typeof content === "function"){
                if (content.prototype  instanceof Component){
                    content = React.createElement(content, args);
                }else {
                    content = content(args);
                }
            } else {
                content = <CellRenderer {...args} />;
            }
            return (
                <Cell key={key} content={content} />
            );
        });

        return(
            <Row key={current[idColumn]} columns={columns} config={config} object={current}>
                {cells}
            </Row>
        );
    });
    return(
        <tbody>
            {rows}
            {children}
        </tbody>
    );
};

if (process.env.NODE_ENV !== 'production'){
    GridBody.propTypes = {
        config : globalConfigPropType,
        objects: PropTypes.arrayOf(PropTypes.object),
        columnKeys: PropTypes.arrayOf(PropTypes.string).isRequired,
        columns: columnsConfigPropType,
        children: PropTypes.any,
        idColumn: PropTypes.string.isRequired
    };
}

export default GridBody;

@@ -967,32 +967,265 @@
               %7D%0A
+            %7D else if (content && typeof content === %22string%22)%7B%0A               // do nothing when content is static%0A            %7D else if (content && typeof content === %22number%22)%7B%0A                // do nothing when content is static%0A
             %7D el

fix test "Should be possible to override the displayValueGetter per column"