'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 _Badge = require('./Badge.scss');

var _Badge2 = _interopRequireDefault(_Badge);

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

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function badgeClasses(tcStyle, onDelete) {
	var _classNames;

	return (0, _classnames2.default)((_classNames = {}, _defineProperty(_classNames, _Badge2.default['tc-badge'], true), _defineProperty(_classNames, 'tc-badge', true), _defineProperty(_classNames, _Badge2.default['tc-badge-outline'], tcStyle === 'outline'), _defineProperty(_classNames, 'tc-badge-outline', tcStyle === 'outline'), _defineProperty(_classNames, _Badge2.default['tc-badge-solid'], tcStyle === 'solid'), _defineProperty(_classNames, 'tc-badge-solid', tcStyle === 'solid'), _defineProperty(_classNames, _Badge2.default['tc-badge-with-icon'], onDelete), _defineProperty(_classNames, 'tc-badge-with-icon', onDelete), _classNames));
}

function badgeLabelClasses(onDelete) {
	var _classNames2;

	return (0, _classnames2.default)((_classNames2 = {}, _defineProperty(_classNames2, _Badge2.default['tc-badge-label'], true), _defineProperty(_classNames2, 'tc-badge-label', true), _defineProperty(_classNames2, _Badge2.default['tc-badge-label-with-icon'], onDelete), _defineProperty(_classNames2, 'tc-badge-label-with-icon', onDelete), _classNames2));
}

function renderDeleteIcon(onDelete) {
	return _react2.default.createElement(_Action2.default, {
		label: 'delete',
		hideLabel: true,
		onClick: onDelete,
		icon: 'talend-cross',
		className: _Badge2.default['tc-badge-delete-icon'] + ' tc-badge-delete-icon'
	});
}

function Badge(_ref) {
	var label = _ref.label,
	    tcStyle = _ref.tcStyle,
	    onDelete = _ref.onDelete;

	return _react2.default.createElement(
		'div',
		{ className: badgeClasses(tcStyle, onDelete) },
		_react2.default.createElement(
			'span',
			{ className: badgeLabelClasses(onDelete) },
			label
		),
		onDelete && renderDeleteIcon(onDelete)
	);
}

Badge.propTypes = {
	label: _react2.default.PropTypes.string,
	tcStyle: _react2.default.PropTypes.string,
	onDelete: _react2.default.PropTypes.func
};

Badge.defaultProps = {
	tcStyle: 'solid'
};

exports.default = Badge;