'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 _CellCheckbox = require('./CellCheckbox.scss');

var _CellCheckbox2 = _interopRequireDefault(_CellCheckbox);

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

/**
 * Cell renderer that displays a checkbox
 */
function CellCheckbox(_ref) {
	var cellData = _ref.cellData,
	    columnData = _ref.columnData,
	    rowData = _ref.rowData,
	    rowIndex = _ref.rowIndex;
	var id = columnData.id,
	    label = columnData.label,
	    _onChange = columnData.onChange;

	return _react2.default.createElement(
		'form',
		{ className: (0, _classnames2.default)('tc-list-checkbox', _CellCheckbox2.default['tc-list-checkbox']) },
		_react2.default.createElement(
			'div',
			{ className: 'checkbox' },
			_react2.default.createElement(
				'label',
				{ htmlFor: id && id + '-' + rowIndex + '-check' },
				_react2.default.createElement('input', {
					id: id && id + '-' + rowIndex + '-check',
					type: 'checkbox',
					onChange: function onChange(e) {
						_onChange(e, rowData);
					},
					checked: cellData
				}),
				_react2.default.createElement(
					'span',
					null,
					_react2.default.createElement(
						'span',
						{ className: 'sr-only' },
						label
					)
				)
			)
		)
	);
}

CellCheckbox.displayName = 'VirtualizedList(CellCheckbox)';
CellCheckbox.propTypes = {
	// The cell value : props.rowData[props.dataKey]
	cellData: _react.PropTypes.string,
	// The custom props passed to <VirtualizedList.Content columnData={}>.
	columnData: _react.PropTypes.shape({
		// The List id. This is used as the checkbox id prefix.
		id: _react.PropTypes.string,
		// The checkbox label.
		label: _react.PropTypes.string,
		// The onChange callback triggered on checkbox toggle.
		onChange: _react.PropTypes.func.isRequired
	}),
	// The collection item.
	rowData: _react.PropTypes.object, // eslint-disable-line
	// The collection item index.
	rowIndex: _react.PropTypes.number
};

exports.default = CellCheckbox;