import _defineProperty from 'babel-runtime/helpers/defineProperty';
import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
import _createClass from 'babel-runtime/helpers/createClass';
import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
import _inherits from 'babel-runtime/helpers/inherits';
var _jsxFileName = 'src/table/TableTbody.jsx';
/**
 * TableTbody.jsx
 *
 * @Author: apple
 * @Date: 2018/3/8 16:34
 */

import React from 'react';
import classNames from 'classnames';
import TableCell from './TableCell';
import Tr from './Tr';
import { isFunction } from '../util/isType';
import listenCssRender from '../util/listenCssRender';

/**
 * @ignore
 * */

var TableTbody = function (_React$Component) {
    _inherits(TableTbody, _React$Component);

    function TableTbody(props, context) {
        _classCallCheck(this, TableTbody);

        var _this = _possibleConstructorReturn(this, (TableTbody.__proto__ || Object.getPrototypeOf(TableTbody)).call(this, props, context));

        _this.getTableTbody = function (el) {
            var tableTbodyRef = _this.props.tableTbodyRef;

            _this.tableTbody = el;
            tableTbodyRef && tableTbodyRef(el);
        };

        return _this;
    }

    _createClass(TableTbody, [{
        key: 'render',
        value: function render() {
            var _this2 = this;

            var _props = this.props,
                tbodyClassName = _props.tbodyClassName,
                data = _props.data,
                expandRowIds = _props.expandRowIds,
                renderColumns = _props.renderColumns,
                selfPrefixCls = _props.selfPrefixCls,
                stripe = _props.stripe,
                rowHeightArray = _props.rowHeightArray,
                position = _props.position,
                rules = _props.rules,
                pubsubEventString = _props.pubsubEventString,
                expandOpt = _props.expandOpt,
                checkbox = _props.checkbox,
                isHover = _props.isHover,
                noDataRender = _props.noDataRender;

            var extended = 0;
            return React.createElement(
                'tbody',
                { className: tbodyClassName, ref: this.getTableTbody, __source: {
                        fileName: _jsxFileName,
                        lineNumber: 52
                    },
                    __self: this
                },
                data.length !== 0 ? data.map(function (elm, i) {
                    var expandRow = expandRowIds.filter(function (item) {
                        return item === i;
                    })[0];
                    var colSpan = renderColumns.length;
                    var rowIndex = i + extended + 1;
                    var classStr = classNames(_defineProperty({}, selfPrefixCls + '-cell-stripe', stripe && !(expandRow === 0 || expandRow) && !!(rowIndex && !(rowIndex % 2))));
                    var trStyle = {
                        height: rowHeightArray[i],
                        expandRowHeight: null
                    };
                    if (expandRow) {
                        trStyle.height = rowHeightArray[2 * i];
                        trStyle.expandRowHeight = rowHeightArray[2 * i + 1];
                    }
                    var trProps = {
                        key: i,
                        id: i,
                        data: data[i],
                        classStr: classStr,
                        elm: elm,
                        rules: rules,
                        trStyle: trStyle,
                        renderColumns: renderColumns,
                        position: position,
                        selfPrefixCls: selfPrefixCls,
                        colSpan: colSpan,
                        pubsubEventString: pubsubEventString,
                        expandOpt: expandOpt,
                        checkbox: checkbox,
                        isHover: isHover
                    };
                    return React.createElement(Tr, Object.assign({}, trProps, {
                        __source: {
                            fileName: _jsxFileName,
                            lineNumber: 87
                        },
                        __self: _this2
                    }));
                }) : position === 'main' && React.createElement(
                    'tr',
                    {
                        __source: {
                            fileName: _jsxFileName,
                            lineNumber: 90
                        },
                        __self: this
                    },
                    React.createElement(TableCell, {
                        className: 'text-center',
                        colSpan: renderColumns.length,
                        style: { padding: '55px', color: '#999' },
                        content: isFunction(noDataRender) ? noDataRender() : noDataRender,
                        __source: {
                            fileName: _jsxFileName,
                            lineNumber: 91
                        },
                        __self: this
                    })
                )
            );
        }
    }]);

    return TableTbody;
}(React.Component);

TableTbody.propTypes = {};
TableTbody.defaultProps = {};


export default TableTbody;