'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _reactVirtualized = require('react-virtualized');

var _RowSelection = require('../RowSelection');

var _RowSelection2 = _interopRequireDefault(_RowSelection);

var _tablerow = require('../utils/tablerow');

var _ListTable = require('./ListTable.scss');

var _ListTable2 = _interopRequireDefault(_ListTable);

var _RowThemes = require('./RowThemes');

var _RowThemes2 = _interopRequireDefault(_RowThemes);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
 * List renderer that renders a react-virtualized Table
 */
function ListTable(props) {
	var children = props.children,
	    collection = props.collection,
	    height = props.height,
	    id = props.id,
	    isSelected = props.isSelected,
	    selectionToggle = props.selectionToggle,
	    sort = props.sort,
	    sortBy = props.sortBy,
	    sortDirection = props.sortDirection,
	    width = props.width;


	var RowTableRenderer = selectionToggle ? (0, _RowSelection2.default)( // eslint-disable-line new-cap
	_reactVirtualized.defaultTableRowRenderer, {
		isSelected: isSelected,
		getRowData: function getRowData(rowProps) {
			return rowProps.rowData;
		}
	}) : _reactVirtualized.defaultTableRowRenderer;

	return _react2.default.createElement(
		_reactVirtualized.Table,
		{
			className: 'tc-list-table ' + _ListTable2.default['tc-list-table'],
			gridClassName: _ListTable2.default.grid,
			headerHeight: 35,
			height: height,
			id: id,
			rowClassName: (0, _classnames2.default)(_RowThemes2.default),
			rowCount: collection.length,
			rowGetter: function rowGetter(_ref) {
				var index = _ref.index;
				return collection[index];
			},
			rowHeight: 50,
			rowRenderer: RowTableRenderer,
			sort: sort,
			sortBy: sortBy,
			sortDirection: sortDirection,
			width: width
		},
		(0, _tablerow.toColumns)(id, _ListTable2.default, children)
	);
}
ListTable.displayName = 'VirtualizedList(ListTable)';
ListTable.propTypes = {
	children: _react.PropTypes.arrayOf(_react.PropTypes.element),
	collection: _react.PropTypes.arrayOf(_react.PropTypes.object),
	height: _react.PropTypes.number,
	id: _react.PropTypes.string,
	isSelected: _react.PropTypes.func,
	selectionToggle: _react.PropTypes.func,
	sort: _react.PropTypes.func,
	sortBy: _react.PropTypes.string,
	sortDirection: _react.PropTypes.string,
	width: _react.PropTypes.number
};

exports.default = ListTable;