'use strict';

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

var _rollupPluginBabelHelpers = require('../../_virtual/_rollupPluginBabelHelpers.js');
var React = require('react');
var constants = require('../../utils/constants.js');
var cls = require('classnames');
var base = require('./variations/_view/base.js');
var base$1 = require('./variations/_size/base.js');
var base$2 = require('./variations/_pilled/base.js');
var base$3 = require('./variations/_transparent/base.js');
var base$4 = require('./variations/_clear/base.js');
var Badge_styles = require('./Badge.styles.js');
var Badge_tokens = require('./Badge.tokens.js');

function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }

var React__default = /*#__PURE__*/_interopDefault(React);
var cls__default = /*#__PURE__*/_interopDefault(cls);

var _excluded = ["children", "className", "style", "text", "contentLeft", "contentRight", "size", "view", "customColor", "customBackgroundColor", "pilled", "transparent", "clear", "maxWidth"];
var badgeRoot = function badgeRoot(Root) {
  return /*#__PURE__*/React.forwardRef(function (props, ref) {
    var _StyledContentLeft, _StyledContentMain, _StyledContentMain2, _StyledContentRight;
    var children = props.children,
      className = props.className,
      style = props.style,
      text = props.text,
      contentLeft = props.contentLeft,
      contentRight = props.contentRight,
      size = props.size,
      view = props.view,
      customColor = props.customColor,
      customBackgroundColor = props.customBackgroundColor,
      _props$pilled = props.pilled,
      pilled = _props$pilled === void 0 ? false : _props$pilled,
      _props$transparent = props.transparent,
      transparent = _props$transparent === void 0 ? false : _props$transparent,
      _props$clear = props.clear,
      clear = _props$clear === void 0 ? false : _props$clear,
      _props$maxWidth = props.maxWidth,
      maxWidth = _props$maxWidth === void 0 ? 'auto' : _props$maxWidth,
      rest = _rollupPluginBabelHelpers.objectWithoutProperties(props, _excluded);
    var pilledClass = pilled ? Badge_tokens.classes.badgePilled : undefined;
    var transparentClass = transparent ? Badge_tokens.classes.badgeTransparent : undefined;
    var clearClass = clear ? Badge_tokens.classes.badgeClear : undefined;
    var truncateClass = maxWidth !== 'auto' ? Badge_tokens.classes.badgeTruncate : undefined;
    var txt = !text && typeof children === 'string' ? children : text;
    var iconOnlyClass = !txt && contentLeft ? Badge_tokens.classes.iconOnly : undefined;
    var BadgeContent = function BadgeContent() {
      if (contentLeft) {
        return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, _StyledContentLeft || (_StyledContentLeft = /*#__PURE__*/React__default.default.createElement(Badge_styles.StyledContentLeft, null, contentLeft)), txt ? _StyledContentMain || (_StyledContentMain = /*#__PURE__*/React__default.default.createElement(Badge_styles.StyledContentMain, {
          className: constants.GRADIENT_TEXT_CLASS
        }, txt)) : children);
      }
      return /*#__PURE__*/React__default.default.createElement(React__default.default.Fragment, null, txt ? _StyledContentMain2 || (_StyledContentMain2 = /*#__PURE__*/React__default.default.createElement(Badge_styles.StyledContentMain, {
        className: constants.GRADIENT_TEXT_CLASS
      }, txt)) : children, contentRight && (_StyledContentRight || (_StyledContentRight = /*#__PURE__*/React__default.default.createElement(Badge_styles.StyledContentRight, null, contentRight))));
    };
    return /*#__PURE__*/React__default.default.createElement(Root, _rollupPluginBabelHelpers.extends({
      ref: ref,
      className: cls__default.default(pilledClass, transparentClass, clearClass, truncateClass, iconOnlyClass, className, {}),
      view: view,
      size: size,
      pilled: pilled,
      transparent: transparent,
      clear: clear,
      style: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, style), {}, _rollupPluginBabelHelpers.defineProperty(_rollupPluginBabelHelpers.defineProperty({
        maxWidth: maxWidth
      }, Badge_tokens.privateTokens.customBackground, customBackgroundColor), Badge_tokens.privateTokens.customColor, customColor))
    }, rest), /*#__PURE__*/React__default.default.createElement(BadgeContent, null));
  });
};
var badgeConfig = {
  name: 'Badge',
  tag: 'div',
  layout: badgeRoot,
  base: Badge_styles.base,
  variations: {
    view: {
      css: base.base
    },
    size: {
      css: base$1.base
    },
    pilled: {
      css: base$2.base,
      attrs: true
    },
    transparent: {
      css: base$3.base,
      attrs: true
    },
    clear: {
      css: base$4.base,
      attrs: true
    }
  },
  defaults: {
    view: 'primary',
    size: 'm'
  }
};

exports.badgeConfig = badgeConfig;
exports.badgeRoot = badgeRoot;
