import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "className", "disabled", "element", "icon", "iconPlacement", "selected", "size", "onClick"];
import cx from 'classnames';
import React, { forwardRef } from 'react';
import Box from '../box';
import Icon from '../icon';
import { UITextBody, UITextDisplay, UITextSmall } from '../typography';
import theme from './theme.css';
var Badge = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var _cx;

  var children = _ref.children,
      className = _ref.className,
      _ref$disabled = _ref.disabled,
      disabled = _ref$disabled === void 0 ? false : _ref$disabled,
      element = _ref.element,
      icon = _ref.icon,
      _ref$iconPlacement = _ref.iconPlacement,
      iconPlacement = _ref$iconPlacement === void 0 ? 'left' : _ref$iconPlacement,
      _ref$selected = _ref.selected,
      selected = _ref$selected === void 0 ? false : _ref$selected,
      _ref$size = _ref.size,
      size = _ref$size === void 0 ? 'medium' : _ref$size,
      onClick = _ref.onClick,
      others = _objectWithoutProperties(_ref, _excluded);

  var renderIcon = function renderIcon() {
    return /*#__PURE__*/React.createElement(Icon, {
      className: theme['icon'],
      color: "teal",
      tint: "darkest"
    }, icon);
  };

  var classNames = cx(theme['badge'], theme["is-".concat(size)], (_cx = {}, _defineProperty(_cx, theme['is-clickable'], onClick), _defineProperty(_cx, theme['is-disabled'], disabled), _defineProperty(_cx, theme['is-selected'], selected), _cx), className);
  var TextElement = size === 'small' ? UITextSmall : size === 'large' ? UITextDisplay : UITextBody;
  var boxElement = element || (onClick ? 'button' : 'div');
  return /*#__PURE__*/React.createElement(Box, _extends({
    className: classNames,
    "data-teamleader-ui": "badge",
    element: boxElement,
    ref: ref,
    onClick: onClick,
    paddingHorizontal: 2,
    type: boxElement === 'button' ? 'button' : undefined
  }, others), icon && iconPlacement === 'left' && renderIcon(), children && /*#__PURE__*/React.createElement(TextElement, {
    className: theme['label'],
    element: "span"
  }, children), icon && iconPlacement === 'right' && renderIcon());
});
Badge.displayName = 'Badge';
export default Badge;