'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});
exports.DISPLAY_MODE_SEARCH = exports.DISPLAY_MODE_DEFAULT = undefined;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _classnames = require('classnames');

var _classnames2 = _interopRequireDefault(_classnames);

var _Header = require('./Header/Header.component');

var _Header2 = _interopRequireDefault(_Header);

var _HeaderInput = require('./Header/HeaderInput.component');

var _HeaderInput2 = _interopRequireDefault(_HeaderInput);

var _Items = require('./Items/Items.component');

var _Items2 = _interopRequireDefault(_Items);

var _ListView = require('./ListView.scss');

var _ListView2 = _interopRequireDefault(_ListView);

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

var DISPLAY_MODE_DEFAULT = exports.DISPLAY_MODE_DEFAULT = 'DISPLAY_MODE_DEFAULT';
var DISPLAY_MODE_SEARCH = exports.DISPLAY_MODE_SEARCH = 'DISPLAY_MODE_SEARCH';

function listviewClasses() {
	return (0, _classnames2.default)(_ListView2.default['tc-listview'], 'tc-listview');
}

function ListView(props) {
	var label = props.displayMode === DISPLAY_MODE_SEARCH ? props.noResultLabel : props.emptyLabel;
	return _react2.default.createElement(
		'div',
		{ className: listviewClasses() },
		_react2.default.createElement(HeaderListView, props),
		props.items && props.items.length ? _react2.default.createElement(ItemsListView, props) : _react2.default.createElement(
			'span',
			{ className: _ListView2.default['empty-message'] },
			label
		)
	);
}

ListView.propTypes = {
	items: _react.PropTypes.arrayOf(_react.PropTypes.object),
	noResultLabel: _react.PropTypes.string
};

ListView.defaultProps = {
	displayMode: DISPLAY_MODE_DEFAULT,
	headerLabel: 'Values',
	emptyLabel: 'This list is empty.',
	noResultLabel: 'No result found.',
	toggleAllLabel: 'All',
	searchPlaceholder: 'Search',
	items: []
};

function ItemsListView(props) {
	return _react2.default.createElement(_Items2.default, {
		items: props.items,
		searchCriteria: props.searchCriteria,
		toggleAllChecked: props.toggleAllChecked,
		toggleAllLabel: props.toggleAllLabel,
		onToggleAll: props.onToggleAll,
		getItemHeight: props.getItemHeight,
		emptyLabel: props.emptyLabel
	});
}

ItemsListView.propTypes = {
	items: ListView.propTypes.items,
	searchCriteria: ListView.propTypes.searchCriteria,
	toggleAllChecked: ListView.propTypes.toggleAllChecked,
	toggleAllLabel: ListView.propTypes.toggleAllLabel,
	onToggleAll: ListView.propTypes.onToggleAll,
	getItemHeight: ListView.propTypes.getItemHeight,
	emptyLabel: _react.PropTypes.string
};

function HeaderListView(props) {
	var displayMode = props.displayMode,
	    onInputChange = props.onInputChange,
	    onAddKeyDown = props.onAddKeyDown,
	    headerInput = props.headerInput,
	    headerDefault = props.headerDefault,
	    headerLabel = props.headerLabel,
	    items = props.items,
	    required = props.required,
	    searchPlaceholder = props.searchPlaceholder;


	switch (displayMode) {
		case DISPLAY_MODE_SEARCH:
			{
				var propsInput = {
					headerInput: headerInput,
					onInputChange: onInputChange,
					onAddKeyDown: onAddKeyDown,
					inputPlaceholder: searchPlaceholder
				};
				return _react2.default.createElement(_HeaderInput2.default, propsInput);
			}
		default:
			{
				var propsDefault = {
					headerDefault: headerDefault,
					headerLabel: headerLabel,
					required: required,
					nbItems: items.length,
					nbItemsSelected: items.filter(function (item) {
						return !!item.checked;
					}).length
				};
				return _react2.default.createElement(_Header2.default, propsDefault);
			}
	}
}

HeaderListView.propTypes = {
	displayMode: ListView.propTypes.displayMode,
	headerDefault: ListView.propTypes.headerDefault,
	headerInput: ListView.propTypes.headerInput,
	onInputChange: ListView.propTypes.onInputChange,
	onAddKeyDown: ListView.propTypes.onAddKeyDown,
	headerLabel: ListView.propTypes.headerLabel,
	searchPlaceholder: ListView.propTypes.searchPlaceholder,
	required: ListView.propTypes.required,
	items: ListView.propTypes.items
};

exports.default = ListView;