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

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

var _Icon2 = _interopRequireDefault(_Icon);

var _CellTitleSelector = require('./CellTitleSelector.component');

var _CellTitleSelector2 = _interopRequireDefault(_CellTitleSelector);

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

var _CellTitle = require('./CellTitle.scss');

var _CellTitle2 = _interopRequireDefault(_CellTitle);

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

var TITLE_MODE_TEXT = _constants.cellTitleDisplayModes.TITLE_MODE_TEXT;

/**
 * Cell that renders the item's title.
 * A title is composed by
 * - an optional icon (rowData[columnData.iconKey])
 * - a button with a click action (columnData.onClick)
 * - actions (rowData[columnData.actionsKey])
 */

function CellTitle(_ref) {
	var cellData = _ref.cellData,
	    columnData = _ref.columnData,
	    rowData = _ref.rowData,
	    rowIndex = _ref.rowIndex;
	var id = columnData.id,
	    onClick = columnData.onClick,
	    actionsKey = columnData.actionsKey,
	    displayModeKey = columnData.displayModeKey,
	    iconKey = columnData.iconKey,
	    onEditCancel = columnData.onEditCancel,
	    onEditSubmit = columnData.onEditSubmit;

	var displayMode = rowData[displayModeKey] || TITLE_MODE_TEXT;
	var titleId = id && id + '-' + rowIndex + '-title-cell';

	return _react2.default.createElement(
		'div',
		{
			id: titleId,
			className: (0, _classnames2.default)('tc-list-title', _CellTitle2.default['tc-list-title'])
		},
		iconKey && rowData[iconKey] && _react2.default.createElement(_Icon2.default, { name: rowData[iconKey], className: _CellTitle2.default.icon }),
		_react2.default.createElement(_CellTitleSelector2.default, {
			id: titleId,
			cellData: cellData,
			className: _CellTitle2.default['main-title'],
			displayMode: displayMode,
			onClick: onClick,
			onEditCancel: onEditCancel,
			onEditSubmit: onEditSubmit,
			rowData: rowData
		}),
		actionsKey && rowData[actionsKey] && displayMode === TITLE_MODE_TEXT && _react2.default.createElement(_Actions.Actions, {
			actions: rowData[actionsKey],
			hideLabel: true,
			link: true
		})
	);
}

CellTitle.displayName = 'VirtualizedList(CellTitle)';
CellTitle.propTypes = {
	// The cell value : props.rowData[props.dataKey]
	cellData: _react.PropTypes.string,
	// The custom props passed to <VirtualizedList.Content columnData={}>.
	columnData: _react.PropTypes.shape({
		// The List id. This is used as the title parts ids prefix.
		id: _react.PropTypes.string,
		// The onClick callback triggered on title main button click.
		onClick: _react.PropTypes.func,
		// The actions property key. Actions = props.rowData[props.actionsKey]
		actionsKey: _react.PropTypes.string,
		// The display mode property key. DisplayMode = props.rowData[props.displayModeKey]
		displayModeKey: _react.PropTypes.string,
		// The icon property key. Icon = props.rowData[props.iconKey]
		iconKey: _react.PropTypes.string,
		// 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
	// The collection item index.
	rowIndex: _react.PropTypes.number
};

exports.default = CellTitle;