'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 _Actions = require('../../Actions/');

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

var _Header2 = _interopRequireDefault(_Header);

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; }

function headerClasses() {
	var _classNames;

	return (0, _classnames2.default)((_classNames = {}, _defineProperty(_classNames, _Header2.default['tc-enumeration-header'], true), _defineProperty(_classNames, 'tc-enumeration-header', true), _classNames));
}

function getAction(action, index) {
	function onClick(event) {
		if (action.onClick) {
			action.onClick(event, { value: event.target.value });
		}
	}

	if (action.displayMode === 'dropdown') {
		return _react2.default.createElement(_Actions.ActionDropdown, {
			noCaret: true,
			key: index + '-enum-header-action',
			label: action.label,
			icon: action.icon,
			onClick: onClick,
			btooltipPlacement: 'bottom',
			inProgress: action.inProgress,
			items: action.items,
			hideLabel: true,
			pullRight: true,
			link: true
		});
	}
	return _react2.default.createElement(_Actions.Action, {
		key: index + '-enum-header-action',
		label: action.label,
		icon: action.icon,
		onClick: onClick,
		btooltipPlacement: 'bottom',
		inProgress: action.inProgress,
		hideLabel: true,
		link: true
	});
}

function Header(_ref) {
	var headerDefault = _ref.headerDefault,
	    required = _ref.required;

	return _react2.default.createElement(
		'header',
		{ className: headerClasses() },
		_react2.default.createElement(
			'span',
			null,
			'Values',
			required && '*'
		),
		_react2.default.createElement(
			'div',
			{ className: 'actions' },
			headerDefault.map(getAction)
		)
	);
}

Header.propTypes = {
	headerDefault: _react.PropTypes.arrayOf(_react.PropTypes.shape(_Actions.Action.propTypes)).isRequired,
	required: _react.PropTypes.bool
};

exports.default = Header;