/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
import _defineProperty from "@babel/runtime/helpers/defineProperty";
var _messageMapper;
import "./index.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
/* eslint-disable @atlaskit/design-system/use-tokens-typography */

import React, { forwardRef } from 'react';
import { Box } from '@atlaskit/primitives/compiled';
import { IconType } from '../../../../../../constants';
import { messages } from '../../../../../../messages';
import { useFlexibleUiOptionContext } from '../../../../../../state/flexible-ui-context';
import AtlaskitIcon from '../../../common/atlaskit-icon';
import ImageIcon from '../../../common/image-icon';
import { withOverrideCss } from '../../../common/with-override-css';
import { getFormattedMessage } from '../../../utils';
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 = {}, _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_messageMapper, IconType.PriorityBlocker, messages.priority_blocker), IconType.PriorityCritical, messages.priority_critical), IconType.PriorityHigh, messages.priority_high), IconType.PriorityHighest, messages.priority_highest), IconType.PriorityLow, messages.priority_low), IconType.PriorityLowest, messages.priority_lowest), IconType.PriorityMajor, messages.priority_major), IconType.PriorityMedium, messages.priority_medium), IconType.PriorityMinor, messages.priority_minor), IconType.PriorityTrivial, messages.priority_trivial), _defineProperty(_messageMapper, IconType.PriorityUndefined, messages.priority_undefined));
var getFormattedMessageFromIcon = function getFormattedMessageFromIcon(icon) {
  if (icon) {
    var descriptor = messageMapper[icon];
    if (descriptor) {
      return getFormattedMessage({
        descriptor: descriptor
      });
    }
  }
};
var renderAtlaskitIcon = function renderAtlaskitIcon(icon, testId) {
  if (icon) {
    return /*#__PURE__*/React.createElement(AtlaskitIcon, {
      icon: icon,
      label: icon,
      testId: "".concat(testId, "-icon")
    });
  }
};
var renderImageIcon = function renderImageIcon(url, testId, hideLoadingSkeleton) {
  if (url) {
    return /*#__PURE__*/React.createElement(ImageIcon, {
      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__*/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 = 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.createElement("span", {
    "data-smart-element": name,
    "data-smart-element-badge": true,
    "data-testid": testId,
    ref: ref,
    style: {
      color: color
    },
    className: ax([styles.container, colorMap[appearance]])
  }, !hideIcon && /*#__PURE__*/React.createElement(Box, {
    as: "span",
    xcss: styles.icon
  }, badgeIcon), /*#__PURE__*/React.createElement(Box, {
    as: "span",
    testId: "".concat(testId, "-label"),
    xcss: styles.text
  }, formattedMessageOrLabel));
});
var _default_1 = withOverrideCss(BaseBadgeRefreshNew);
export default _default_1;
export var toBadgeProps = function toBadgeProps(label) {
  // Don't render the element if its 0
  return label !== '0' && label ? {
    label: label
  } : undefined;
};