'use strict';

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

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _constants = require('./utils/constants');

var _dictionary = require('./utils/dictionary');

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

var _ListTable2 = _interopRequireDefault(_ListTable);

var _ListGrid = require('./ListGrid');

var _ListGrid2 = _interopRequireDefault(_ListGrid);

var _PropTypes = require('./PropTypes');

var _PropTypes2 = _interopRequireDefault(_PropTypes);

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

var TABLE = _constants.listTypes.TABLE;

/**
 * Select the ListGrid row renderer to use
 * @param type The row renderer type
 */

function getRowRenderer(type) {
	var rowRenderer = _dictionary.rowDictionary[type];
	if (!rowRenderer) {
		var rowRendererTypes = [TABLE].concat(Object.keys(_dictionary.rowDictionary));
		throw new Error('Unknown row renderer in Virtualized List : ' + type + '. ' + ('Possible values are [' + rowRendererTypes + '].'));
	}
	return rowRenderer;
}

/**
 * Component that maps list types to the corresponding component
 */
function RendererSelector(props) {
	var children = props.children,
	    collection = props.collection,
	    height = props.height,
	    id = props.id,
	    isSelected = props.isSelected,
	    rowHeight = props.rowHeight,
	    selectionToggle = props.selectionToggle,
	    sort = props.sort,
	    sortBy = props.sortBy,
	    sortDirection = props.sortDirection,
	    type = props.type,
	    width = props.width;


	if (type === TABLE) {
		return _react2.default.createElement(
			_ListTable2.default,
			{
				collection: collection,
				height: height,
				id: id,
				isSelected: isSelected,
				selectionToggle: selectionToggle,
				sort: sort,
				sortBy: sortBy,
				sortDirection: sortDirection,
				width: width
			},
			children
		);
	}
	return _react2.default.createElement(
		_ListGrid2.default,
		{
			collection: collection,
			height: height,
			id: id,
			isSelected: isSelected,
			rowHeight: rowHeight,
			rowRenderer: getRowRenderer(type),
			selectionToggle: selectionToggle,
			width: width
		},
		children
	);
}
RendererSelector.displayName = 'VirtualizedList(RendererSelector)';
RendererSelector.propTypes = _extends({}, _PropTypes2.default, {
	height: _react.PropTypes.number,
	width: _react.PropTypes.number
});
RendererSelector.defaultProps = {
	type: TABLE
};

exports.default = RendererSelector;