/* index.tsx generated by @compiled/babel-plugin v0.38.1 */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.toBadgeProps = exports.default = void 0;
require("./index.compiled.css");
var _runtime = require("@compiled/react/runtime");
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _react = _interopRequireWildcard(require("react"));
var _compiled = require("@atlaskit/primitives/compiled");
var _constants = require("../../../../../../constants");
var _messages = require("../../../../../../messages");
var _flexibleUiContext = require("../../../../../../state/flexible-ui-context");
var _atlaskitIcon = _interopRequireDefault(require("../../../common/atlaskit-icon"));
var _imageIcon = _interopRequireDefault(require("../../../common/image-icon"));
var _withOverrideCss = require("../../../common/with-override-css");
var _utils = require("../../../utils");
var _messageMapper;
/* eslint-disable @atlaskit/design-system/use-tokens-typography */
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
var styles = {
  container: "_zulp1b66 _1e0c116y _4cvr1h6o _1ul91ns9",
  icon: "_1e0c116y _v4pn116y _1b94116y _1ii7116y _4t3i7vkz _bna77vkz _1xjx7vkz _17527vkz _ca0qze3t _14bqze3t _1oh2ze3t _i2i3ze3t _u5f3ze3t _3tceze3t _99ztze3t _uhasze3t _n3tdze3t _1ym6ze3t _1m2uze3t _5jw9ze3t _19bvze3t _1xr1ze3t _9n9oze3t _7wy9ze3t _1bsb7vkz _mezj7vkz _e2oo7vkz _w8l57vkz _s7n4nkob _rtqbnkob _e4kmnkob _z239nkob",
  text: "_11c8wadc"
};
var colorMap = {
  subtle: "_syaz1rpy",
  default: "_syazazsu"
};
var messageMapper = (_messageMapper = {}, (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)(_messageMapper, _constants.IconType.PriorityBlocker, _messages.messages.priority_blocker), _constants.IconType.PriorityCritical, _messages.messages.priority_critical), _constants.IconType.PriorityHigh, _messages.messages.priority_high), _constants.IconType.PriorityHighest, _messages.messages.priority_highest), _constants.IconType.PriorityLow, _messages.messages.priority_low), _constants.IconType.PriorityLowest, _messages.messages.priority_lowest), _constants.IconType.PriorityMajor, _messages.messages.priority_major), _constants.IconType.PriorityMedium, _messages.messages.priority_medium), _constants.IconType.PriorityMinor, _messages.messages.priority_minor), _constants.IconType.PriorityTrivial, _messages.messages.priority_trivial), (0, _defineProperty2.default)(_messageMapper, _constants.IconType.PriorityUndefined, _messages.messages.priority_undefined));
var getFormattedMessageFromIcon = function getFormattedMessageFromIcon(icon) {
  if (icon) {
    var descriptor = messageMapper[icon];
    if (descriptor) {
      return (0, _utils.getFormattedMessage)({
        descriptor: descriptor
      });
    }
  }
};
var renderAtlaskitIcon = function renderAtlaskitIcon(icon, testId) {
  if (icon) {
    return /*#__PURE__*/_react.default.createElement(_atlaskitIcon.default, {
      icon: icon,
      label: icon,
      testId: "".concat(testId, "-icon")
    });
  }
};
var renderImageIcon = function renderImageIcon(url, testId, hideLoadingSkeleton) {
  if (url) {
    return /*#__PURE__*/_react.default.createElement(_imageIcon.default, {
      testId: testId,
      url: url,
      hideLoadingSkeleton: hideLoadingSkeleton
    });
  }
};
/**
 * A base element that displays some text with an associated icon.
 * @internal
 * @param {BaseBadgeElementProps} BaseBadgeElementProps - The props necessary for the Badge.
 * @see CommentCount
 * @see ViewCount
 * @see ReactCount
 * @see VoteCount
 * @see SubscriberCount
 * @see Priority
 * @see ProgrammingLanguage
 * @see Provider
 */
var BaseBadgeRefreshNew = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var _ref$appearance = _ref.appearance,
    appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
    _ref$hideIcon = _ref.hideIcon,
    hideIcon = _ref$hideIcon === void 0 ? false : _ref$hideIcon,
    icon = _ref.icon,
    label = _ref.label,
    name = _ref.name,
    _ref$testId = _ref.testId,
    testId = _ref$testId === void 0 ? 'smart-element-badge' : _ref$testId,
    url = _ref.url,
    color = _ref.color;
  var ui = (0, _flexibleUiContext.useFlexibleUiOptionContext)();
  var formattedMessageOrLabel = getFormattedMessageFromIcon(icon) || label;
  var badgeIcon = renderAtlaskitIcon(icon, testId) || renderImageIcon(url, testId, ui === null || ui === void 0 ? void 0 : ui.hideLoadingSkeleton);
  if (!formattedMessageOrLabel || !badgeIcon) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement("span", {
    "data-smart-element": name,
    "data-smart-element-badge": true,
    "data-testid": testId,
    ref: ref,
    style: {
      color: color
    },
    className: (0, _runtime.ax)([styles.container, colorMap[appearance]])
  }, !hideIcon && /*#__PURE__*/_react.default.createElement(_compiled.Box, {
    as: "span",
    xcss: styles.icon
  }, badgeIcon), /*#__PURE__*/_react.default.createElement(_compiled.Box, {
    as: "span",
    testId: "".concat(testId, "-label"),
    xcss: styles.text
  }, formattedMessageOrLabel));
});
var _default = exports.default = (0, _withOverrideCss.withOverrideCss)(BaseBadgeRefreshNew);
var toBadgeProps = exports.toBadgeProps = function toBadgeProps(label) {
  // Don't render the element if its 0
  return label !== '0' && label ? {
    label: label
  } : undefined;
};