'use strict';

Object.defineProperty(exports, "__esModule", {
	value: true
});

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _reactBootstrap = require('react-bootstrap');

var _uuid = require('uuid');

var _uuid2 = _interopRequireDefault(_uuid);

var _Icon = require('../../../Icon');

var _Icon2 = _interopRequireDefault(_Icon);

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

function getIcon(selected) {
	switch (selected) {
		case 'table':
			return 'talend-table';
		case 'large':
			return 'talend-expanded';
		case 'tile':
			return 'talend-tiles';
		default:
			return 'talend-table';
	}
}

function getLabel(selected) {
	switch (selected) {
		case 'table':
			return 'Table';
		case 'large':
			return 'Expanded';
		case 'tile':
			return 'Tile';
		default:
			return 'Table';
	}
}

var options = ['table', 'large', 'tile'];

function SelectDisplayMode(_ref) {
	var id = _ref.id,
	    mode = _ref.mode,
	    displayModes = _ref.displayModes,
	    onChange = _ref.onChange;

	var selected = mode || 'table';
	var modes = displayModes || options;
	var displayIcon = _react2.default.createElement(_Icon2.default, { name: getIcon(selected) });

	function onChangeMode(value, event) {
		return onChange(event, value);
	}

	function getMenuItem(option) {
		return _react2.default.createElement(
			_reactBootstrap.MenuItem,
			{
				id: id && id + '-' + option,
				key: option,
				eventKey: option
			},
			_react2.default.createElement(_Icon2.default, { name: getIcon(option) }),
			getLabel(option)
		);
	}

	return _react2.default.createElement(
		_reactBootstrap.Nav,
		null,
		_react2.default.createElement(
			_reactBootstrap.NavDropdown,
			{
				id: id || _uuid2.default.v4(),
				title: displayIcon,
				onSelect: onChangeMode
			},
			modes.map(function (option) {
				return getMenuItem(option);
			})
		)
	);
}

SelectDisplayMode.propTypes = {
	id: _react.PropTypes.string,
	mode: _react.PropTypes.string,
	displayModes: _react.PropTypes.arrayOf(_react.PropTypes.string),
	onChange: _react.PropTypes.func.isRequired
};

exports.default = SelectDisplayMode;