'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 _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

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

var _RowSelection2 = _interopRequireDefault(_RowSelection);

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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 getRowSelectionRenderer(WrappedComponent, _ref) {
	var isSelected = _ref.isSelected,
	    getRowData = _ref.getRowData;

	function RowSelection(props) {
		var rowData = getRowData(props);

		var enhancedClassNames = (0, _classnames2.default)(props.className, _RowSelection2.default['row-selection'], _defineProperty({}, _RowSelection2.default.selected, isSelected(rowData)), { selected: isSelected(rowData) });
		return _react2.default.createElement(WrappedComponent, _extends({}, props, { className: enhancedClassNames }));
	}
	RowSelection.propTypes = WrappedComponent.propTypes;
	RowSelection.displayName = 'RowSelection(' + WrappedComponent.displayName + ')';

	return RowSelection;
}

exports.default = getRowSelectionRenderer;