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

var _SelectAll2 = _interopRequireDefault(_SelectAll);

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

function SelectAll(_ref) {
	var id = _ref.id,
	    items = _ref.items,
	    isSelected = _ref.isSelected,
	    onToggleAll = _ref.onToggleAll;

	var isAllSelected = function isAllSelected() {
		return items.length > 0 && items.findIndex(function (item) {
			return !isSelected(item);
		}) < 0;
	};
	var checkboxId = id && id + '-check-all';
	return _react2.default.createElement(
		'form',
		{ className: 'navbar-form navbar-left' },
		_react2.default.createElement(
			'div',
			{ className: (0, _classnames2.default)('checkbox-inline navbar-text', _SelectAll2.default['tc-list-toolbar-select-all']) },
			_react2.default.createElement(
				'label',
				{ className: 'tc-list-toolbar-select-all', htmlFor: checkboxId },
				_react2.default.createElement('input', {
					id: checkboxId,
					type: 'checkbox',
					onChange: function onChange(event) {
						onToggleAll(event, items);
					},
					checked: isAllSelected(),
					disabled: !items.length
				}),
				_react2.default.createElement(
					'span',
					null,
					'Select All'
				)
			)
		)
	);
}

SelectAll.propTypes = {
	id: _react2.default.PropTypes.string,
	items: _react2.default.PropTypes.arrayOf(_react2.default.PropTypes.object).isRequired,
	isSelected: _react2.default.PropTypes.func.isRequired,
	onToggleAll: _react2.default.PropTypes.func.isRequired
};

exports.default = SelectAll;