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

var _Action2 = _interopRequireDefault(_Action);

var _TabBar = require('./TabBar.scss');

var _TabBar2 = _interopRequireDefault(_TabBar);

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

function Tab(_ref) {
	var item = _ref.item,
	    onClick = _ref.onClick,
	    isSelected = _ref.isSelected;

	var onSelect = function onSelect(event) {
		onClick(event, item);
	};
	return _react2.default.createElement(
		'li',
		{ className: (0, _classnames2.default)(['tc-tab-bar-action', isSelected && 'active']) },
		_react2.default.createElement(_Action2.default, {
			bsStyle: 'link',
			id: item.id,
			label: item.label,
			onClick: onSelect
		})
	);
}

Tab.propTypes = {
	item: _react2.default.PropTypes.shape({
		id: _react2.default.PropTypes.string,
		key: _react2.default.PropTypes.string.isRequired,
		label: _react2.default.PropTypes.string.isRequired
	}).isRequired,
	isSelected: _react2.default.PropTypes.bool,
	onClick: _react2.default.PropTypes.func.isRequired
};

function TabBar(_ref2) {
	var items = _ref2.items,
	    onSelect = _ref2.onSelect,
	    selected = _ref2.selected;

	return _react2.default.createElement(
		'nav',
		{ className: (0, _classnames2.default)(['nav', 'tc-tab-bar', _TabBar2.default['tc-tab-bar']]) },
		_react2.default.createElement(
			'ul',
			{ className: 'nav nav-tabs tc-tab-bar-actions' },
			items.map(function (item) {
				return _react2.default.createElement(Tab, { key: item.key, onClick: onSelect, isSelected: selected === item.key, item: item });
			})
		)
	);
}

TabBar.propTypes = {
	items: _react2.default.PropTypes.arrayOf(_react2.default.PropTypes.shape({
		id: _react2.default.PropTypes.string,
		key: _react2.default.PropTypes.string.isRequired,
		label: _react2.default.PropTypes.string.isRequired
	})).isRequired,
	onSelect: _react2.default.PropTypes.func.isRequired,
	selected: _react2.default.PropTypes.string
};

TabBar.Tab = Tab;

exports.default = TabBar;