'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _random = require('lodash/random');

var _random2 = _interopRequireDefault(_random);

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

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

var _RowSelection2 = _interopRequireDefault(_RowSelection);

var _RowPlaceholder = require('./RowPlaceholder.scss');

var _RowPlaceholder2 = _interopRequireDefault(_RowPlaceholder);

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

/**
 * Higher order row-renderer that wrap the provided row renderer.
 * It manages row selection classname and inject it to the row renderer props.
 */
function getRowRenderer(_ref) {
	var selectionToggle = _ref.selectionToggle,
	    isSelected = _ref.isSelected;

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

	function Row(props) {
		var isScrolling = props.isScrolling;


		if (isScrolling) {
			// create a skeleton to avoid many paint during the scroll
			// improve the performance on the browsers
			// waiting guidelines from UX
			return _react2.default.createElement(
				'div',
				props,
				_react2.default.createElement('div', {
					className: _RowPlaceholder2.default['row-placeholder'],
					style: {
						width: (0, _random2.default)(15, 50) + '%'
					}
				})
			);
		}
		return _react2.default.createElement(RowTableRender, props);
	}
	Row.propTypes = _reactVirtualized.defaultTableRowRenderer.propTypes;
	Row.displayName = 'VirtualizedList(RowRender)';

	return Row;
}

exports.default = getRowRenderer;