'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 _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 Logo(_ref) {
	var id = _ref.id,
	    isFull = _ref.isFull,
	    onClick = _ref.onClick;

	var icon = isFull ? 'talend-logo' : 'talend-logo-square';
	var itemClassName = (0, _classnames2.default)(['tc-header-bar-action', !isFull && 'separated']);
	var actionClassName = (0, _classnames2.default)(['tc-header-bar-logo', isFull && 'full']);
	return _react2.default.createElement(
		'li',
		{ className: itemClassName },
		_react2.default.createElement(_Action2.default, {
			bsStyle: 'link',
			className: actionClassName,
			hideLabel: true,
			id: id,
			label: 'Go to Portal',
			icon: icon,
			onClick: onClick,
			tooltipPlacement: 'bottom'
		})
	);
}

Logo.propTypes = {
	id: _react2.default.PropTypes.string,
	isFull: _react2.default.PropTypes.bool,
	onClick: _react2.default.PropTypes.func.isRequired
};

function Brand(_ref2) {
	var id = _ref2.id,
	    isSeparated = _ref2.isSeparated,
	    name = _ref2.name,
	    onClick = _ref2.onClick;

	var className = (0, _classnames2.default)(['tc-header-bar-action', isSeparated && 'separated']);
	return _react2.default.createElement(
		'li',
		{ className: className },
		_react2.default.createElement(_Action2.default, {
			bsStyle: 'link',
			className: 'tc-header-bar-brand',
			id: id,
			label: name,
			onClick: onClick,
			tooltipPlacement: 'bottom'
		})
	);
}

Brand.propTypes = {
	id: _react2.default.PropTypes.string,
	isSeparated: _react2.default.PropTypes.bool,
	name: _react2.default.PropTypes.string.isRequired,
	onClick: _react2.default.PropTypes.func.isRequired
};

function Environment(props) {
	return _react2.default.createElement(
		'li',
		{ className: 'tc-header-bar-action' },
		_react2.default.createElement(_ActionDropdown2.default, {
			bsStyle: 'link',
			icon: 'talend-environment',
			id: props.id,
			items: props.items,
			label: props.label,
			tooltipPlacement: 'bottom'
		})
	);
}

Environment.propTypes = {
	id: _react2.default.PropTypes.string,
	items: _ActionDropdown2.default.propTypes.items,
	label: _ActionDropdown2.default.propTypes.label
};

function Search(props) {
	return _react2.default.createElement(
		'li',
		{ className: 'tc-header-bar-action separated flex' },
		_react2.default.createElement(_Typeahead2.default, props)
	);
}

Search.propTypes = _Typeahead2.default.propTypes;

function Help(_ref3) {
	var id = _ref3.id,
	    onClick = _ref3.onClick;

	return _react2.default.createElement(
		'li',
		{ className: 'tc-header-bar-action' },
		_react2.default.createElement(_Action2.default, {
			bsStyle: 'link',
			icon: 'talend-question-circle',
			id: id,
			label: 'Help',
			onClick: onClick,
			tooltipPlacement: 'bottom'
		})
	);
}

Help.propTypes = {
	id: _react2.default.PropTypes.string,
	onClick: _react2.default.PropTypes.func.isRequired
};

function User(_ref4) {
	var id = _ref4.id,
	    items = _ref4.items,
	    name = _ref4.name;

	return _react2.default.createElement(
		'li',
		{ className: 'tc-header-bar-action separated' },
		_react2.default.createElement(_ActionDropdown2.default, {
			bsStyle: 'link',
			icon: 'talend-user-circle',
			id: id,
			items: items,
			label: name,
			noCaret: true,
			tooltipPlacement: 'bottom'
		})
	);
}

User.propTypes = {
	id: _react2.default.PropTypes.string,
	items: _ActionDropdown2.default.propTypes.items,
	name: _ActionDropdown2.default.propTypes.label
};

function Products(_ref5) {
	var id = _ref5.id,
	    items = _ref5.items;

	return _react2.default.createElement(
		'li',
		{ className: 'tc-header-bar-action' },
		_react2.default.createElement(_ActionDropdown2.default, {
			bsStyle: 'link',
			className: 'tc-header-bar-products',
			id: id,
			icon: 'talend-launcher',
			items: items,
			label: 'Apps',
			noCaret: true,
			pullRight: true,
			tooltipPlacement: 'bottom'
		})
	);
}

Products.propTypes = {
	id: _react2.default.PropTypes.string,
	items: _ActionDropdown2.default.propTypes.items
};

function HeaderBar(props) {
	return _react2.default.createElement(
		'nav',
		{ className: (0, _classnames2.default)(['tc-header-bar, ' + _HeaderBar2.default['tc-header-bar']]) },
		_react2.default.createElement(
			'ul',
			{ className: 'tc-header-bar-actions' },
			_react2.default.createElement(Logo, props.logo),
			_react2.default.createElement(Brand, _extends({}, props.brand, { isSeparated: !!props.env })),
			props.env && _react2.default.createElement(Environment, props.env)
		),
		_react2.default.createElement(
			'ul',
			{ className: 'tc-header-bar-actions right' },
			props.search && _react2.default.createElement(Search, props.search),
			props.help && _react2.default.createElement(Help, props.help),
			props.user && _react2.default.createElement(User, props.user),
			props.products && _react2.default.createElement(Products, 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)
};

exports.default = HeaderBar;