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

var _Action2 = _interopRequireDefault(_Action);

var _ActionDropdown = require('../Actions/ActionDropdown');

var _ActionDropdown2 = _interopRequireDefault(_ActionDropdown);

var _ActionSplitDropdown = require('../Actions/ActionSplitDropdown');

var _ActionSplitDropdown2 = _interopRequireDefault(_ActionSplitDropdown);

var _Typeahead = require('../Typeahead');

var _Typeahead2 = _interopRequireDefault(_Typeahead);

var _HeaderBar = require('./HeaderBar.scss');

var _HeaderBar2 = _interopRequireDefault(_HeaderBar);

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 _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

function getRenderers(renderers) {
	return _extends({
		Action: _Action2.default,
		ActionDropdown: _ActionDropdown2.default,
		ActionSplitDropdown: _ActionSplitDropdown2.default,
		Typeahead: _Typeahead2.default
	}, renderers || {});
}

function Logo(_ref) {
	var isFull = _ref.isFull,
	    renderers = _ref.renderers,
	    props = _objectWithoutProperties(_ref, ['isFull', 'renderers']);

	var icon = isFull ? 'talend-logo' : 'talend-logo-square';
	var itemClassName = (0, _classnames2.default)(_HeaderBar2.default['tc-header-bar-action'], _defineProperty({}, _HeaderBar2.default.separated, !isFull));
	var actionClassName = (0, _classnames2.default)(_HeaderBar2.default['tc-header-bar-logo'], _defineProperty({}, _HeaderBar2.default.full, isFull));

	return _react2.default.createElement(
		'li',
		{ className: itemClassName },
		_react2.default.createElement(renderers.Action, _extends({
			bsStyle: 'link',
			className: actionClassName,
			hideLabel: true,
			label: 'Go to Portal',
			icon: icon,
			tooltipPlacement: 'bottom'
		}, props))
	);
}

Logo.propTypes = {
	isFull: _react2.default.PropTypes.bool,
	renderers: _react2.default.PropTypes.shape({
		Action: _react2.default.PropTypes.func
	})
};

function Brand(_ref2) {
	var name = _ref2.name,
	    isSeparated = _ref2.isSeparated,
	    renderers = _ref2.renderers,
	    props = _objectWithoutProperties(_ref2, ['name', 'isSeparated', 'renderers']);

	var className = (0, _classnames2.default)(_HeaderBar2.default['tc-header-bar-action'], _defineProperty({}, _HeaderBar2.default.separated, isSeparated));

	return _react2.default.createElement(
		'li',
		{ className: className },
		_react2.default.createElement(renderers.Action, _extends({
			bsStyle: 'link',
			className: _HeaderBar2.default['tc-header-bar-brand'],
			tooltipPlacement: 'bottom',
			label: name
		}, props))
	);
}

Brand.propTypes = {
	isSeparated: _react2.default.PropTypes.bool,
	renderers: _react2.default.PropTypes.shape({
		Action: _react2.default.PropTypes.func
	})
};

function Environment(_ref3) {
	var renderers = _ref3.renderers,
	    props = _objectWithoutProperties(_ref3, ['renderers']);

	return _react2.default.createElement(
		'li',
		{ className: _HeaderBar2.default['tc-header-bar-action'] },
		_react2.default.createElement(renderers.ActionDropdown, _extends({
			bsStyle: 'link',
			icon: 'talend-environment',
			tooltipPlacement: 'bottom'
		}, props))
	);
}

Environment.propTypes = {
	renderers: _react2.default.PropTypes.shape({
		ActionDropdown: _react2.default.PropTypes.func
	})
};

function Search(_ref4) {
	var renderers = _ref4.renderers,
	    props = _objectWithoutProperties(_ref4, ['renderers']);

	var className = (0, _classnames2.default)(_HeaderBar2.default['tc-header-bar-action'], _HeaderBar2.default['tc-header-bar-search'], _HeaderBar2.default.separated, _HeaderBar2.default.flex);

	return _react2.default.createElement(
		'li',
		{ className: className },
		_react2.default.createElement(
			'form',
			{ className: 'navbar-form navbar-right', role: 'search' },
			_react2.default.createElement(renderers.Typeahead, props)
		)
	);
}

Search.propTypes = _Typeahead2.default.propTypes;
Search.propTypes.renderers = _react2.default.PropTypes.shape({
	Typeahead: _react2.default.PropTypes.func
});

function Help(_ref5) {
	var renderers = _ref5.renderers,
	    props = _objectWithoutProperties(_ref5, ['renderers']);

	var global = _extends({
		bsStyle: 'link',
		icon: 'talend-question-circle',
		label: 'Help',
		tooltipPlacement: 'bottom'
	}, props);

	return _react2.default.createElement(
		'li',
		{ className: _HeaderBar2.default['tc-header-bar-action'] },
		props.items && props.items.length ? _react2.default.createElement(renderers.ActionSplitDropdown, _extends({ pullRight: true }, global)) : _react2.default.createElement(renderers.Action, global)
	);
}

Help.propTypes = {
	renderers: _react2.default.PropTypes.shape({
		ActionSplitDropdown: _react2.default.PropTypes.func,
		Action: _react2.default.PropTypes.func
	})
};

function User(_ref6) {
	var name = _ref6.name,
	    renderers = _ref6.renderers,
	    props = _objectWithoutProperties(_ref6, ['name', 'renderers']);

	var className = (0, _classnames2.default)(_HeaderBar2.default['tc-header-bar-action'], _HeaderBar2.default.separated);

	return _react2.default.createElement(
		'li',
		{ className: className },
		_react2.default.createElement(renderers.ActionDropdown, _extends({
			bsStyle: 'link',
			icon: 'talend-user-circle',
			pullRight: true,
			tooltipPlacement: 'bottom',
			label: name
		}, props))
	);
}

User.propTypes = {
	renderers: _react2.default.PropTypes.shape({
		ActionDropdown: _react2.default.PropTypes.func
	})
};

function Products(_ref7) {
	var renderers = _ref7.renderers,
	    props = _objectWithoutProperties(_ref7, ['renderers']);

	return _react2.default.createElement(
		'li',
		{ className: _HeaderBar2.default['tc-header-bar-action'] },
		_react2.default.createElement(renderers.ActionDropdown, _extends({
			bsStyle: 'link',
			className: _HeaderBar2.default['tc-header-bar-products'],
			icon: 'talend-launcher',
			label: 'Apps',
			pullRight: true,
			tooltipPlacement: 'bottom'
		}, props))
	);
}

Products.propTypes = {
	renderers: _react2.default.PropTypes.shape({
		ActionDropdown: _react2.default.PropTypes.func
	})
};

function HeaderBar(props) {
	var renderers = getRenderers(props.renderers);
	var Components = _extends({
		Logo: Logo,
		Brand: Brand,
		Environment: Environment,
		Search: Search,
		User: User,
		Help: Help,
		Products: Products
	}, props.renderers || {});

	return _react2.default.createElement(
		'nav',
		{ className: (0, _classnames2.default)(_HeaderBar2.default['tc-header-bar'], 'tc-header-bar') },
		_react2.default.createElement(
			'ul',
			{ className: _HeaderBar2.default['tc-header-bar-actions'] },
			_react2.default.createElement(Components.Logo, _extends({ renderers: renderers }, props.logo)),
			_react2.default.createElement(Components.Brand, _extends({ renderers: renderers }, props.brand, { isSeparated: !!props.env })),
			props.env && _react2.default.createElement(Components.Environment, _extends({ renderers: renderers }, props.env))
		),
		_react2.default.createElement(
			'ul',
			{ className: (0, _classnames2.default)(_HeaderBar2.default['tc-header-bar-actions'], _HeaderBar2.default.right) },
			props.search && _react2.default.createElement(Components.Search, _extends({ renderers: renderers }, props.search)),
			props.help && _react2.default.createElement(Components.Help, _extends({ renderers: renderers }, props.help)),
			props.user && _react2.default.createElement(Components.User, _extends({ renderers: renderers }, props.user)),
			props.products && _react2.default.createElement(Components.Products, _extends({ renderers: renderers }, props.products))
		)
	);
}

HeaderBar.Logo = Logo;
HeaderBar.Brand = Brand;
HeaderBar.Environment = Environment;
HeaderBar.Search = Search;
HeaderBar.Help = Help;
HeaderBar.User = User;
HeaderBar.Products = Products;

HeaderBar.propTypes = {
	logo: _react2.default.PropTypes.shape(Logo.propTypes).isRequired,
	brand: _react2.default.PropTypes.shape(Brand.propTypes).isRequired,
	env: _react2.default.PropTypes.shape(Environment.propTypes),
	search: _react2.default.PropTypes.shape(Search.propTypes),
	help: _react2.default.PropTypes.shape(Help.propTypes),
	user: _react2.default.PropTypes.shape(User.propTypes),
	products: _react2.default.PropTypes.shape(Products.propTypes),
	renderers: _react2.default.PropTypes.shape({
		Logo: _react2.default.PropTypes.func,
		Brand: _react2.default.PropTypes.func,
		Environment: _react2.default.PropTypes.func,
		Search: _react2.default.PropTypes.func,
		User: _react2.default.PropTypes.func,
		Products: _react2.default.PropTypes.func
	})
};

exports.default = HeaderBar;