'use strict';

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

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _constants = require('../utils/constants');

var _CellTitleInput = require('./CellTitleInput.component');

var _CellTitleInput2 = _interopRequireDefault(_CellTitleInput);

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

var TITLE_MODE_TEXT = _constants.cellTitleDisplayModes.TITLE_MODE_TEXT,
    TITLE_MODE_INPUT = _constants.cellTitleDisplayModes.TITLE_MODE_INPUT;

/**
 * Component that selects and renders the requested title display mode
 */

function CellTitleSelector(props) {
	var id = props.id,
	    cellData = props.cellData,
	    className = props.className,
	    displayMode = props.displayMode,
	    _onClick = props.onClick,
	    onEditSubmit = props.onEditSubmit,
	    onEditCancel = props.onEditCancel,
	    rowData = props.rowData;


	if (displayMode === TITLE_MODE_INPUT) {
		return _react2.default.createElement(_CellTitleInput2.default, {
			id: id && id + '-input',
			cellData: cellData,
			rowData: rowData,
			onEditSubmit: onEditSubmit,
			onEditCancel: onEditCancel
		});
	}

	if (_onClick) {
		return _react2.default.createElement(
			_reactBootstrap.Button,
			{
				id: id && id + '-btn',
				className: className,
				onClick: function onClick(event) {
					return _onClick(event, rowData);
				},
				role: 'link',
				bsStyle: 'link'
			},
			cellData
		);
	}

	return _react2.default.createElement(
		'span',
		{ id: id, className: className },
		cellData
	);
}

CellTitleSelector.propTypes = {
	/** The id prefix. */
	id: _react.PropTypes.string,
	/** The input value. */
	cellData: _react.PropTypes.string.isRequired,
	/** The title element className. */
	className: _react.PropTypes.string,
	/** The display mode. */
	displayMode: _react.PropTypes.oneOf([TITLE_MODE_TEXT, TITLE_MODE_INPUT]),
	/** The onClick callback triggered on title main button click. */
	onClick: _react.PropTypes.func,
	/** Input mode : the cancel callback on ESC keydown. */
	onEditCancel: _react.PropTypes.func,
	/** Input mode : the submit callback on ENTER keydown or blur. */
	onEditSubmit: _react.PropTypes.func,
	/** The collection item. */
	rowData: _react.PropTypes.object // eslint-disable-line react/forbid-prop-types
};

exports.default = CellTitleSelector;