/* index.tsx generated by @compiled/babel-plugin v0.39.1 */
/* eslint-disable @atlaskit/design-system/use-tokens-typography */
import "./index.compiled.css";
import { ax, ix } from "@compiled/react/runtime";
import React, { forwardRef } from 'react';
import { fg } from '@atlaskit/platform-feature-flags';
import { Box } from '@atlaskit/primitives/compiled';
import { IconType, InternalActionName } from '../../../../../../constants';
import { messages } from '../../../../../../messages';
import { useFlexibleUiContext, 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';
const styles = {
  container: "_zulp1b66 _1e0c116y _4cvr1h6o _1ul91ns9",
  containerLarge: "_zulpu2gc _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",
  iconLarge: "_4t3i1tcg _bna71tcg _1xjx1tcg _17521tcg _1bsb1tcg _mezj1tcg _e2oo1tcg _w8l51tcg",
  text: "_11c8wadc"
};
const colorMap = {
  subtle: "_syaz1rpy",
  default: "_syazazsu"
};
const 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,
  [IconType.PriorityUndefined]: messages.priority_undefined
};
const getFormattedMessageFromIcon = icon => {
  if (icon) {
    const descriptor = messageMapper[icon];
    if (descriptor) {
      return getFormattedMessage({
        descriptor
      });
    }
  }
};
const renderAtlaskitIcon = (icon, testId) => {
  if (icon) {
    return /*#__PURE__*/React.createElement(AtlaskitIcon, {
      icon: icon,
      label: icon,
      testId: `${testId}-icon`
    });
  }
};
const 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
 */
const BaseBadgeRefreshNew = /*#__PURE__*/forwardRef(({
  appearance = 'default',
  hideIcon = false,
  icon,
  label,
  name,
  testId = 'smart-element-badge',
  url,
  color,
  iconSize = 'default'
}, ref) => {
  const ui = useFlexibleUiOptionContext();
  const formattedMessageOrLabel = getFormattedMessageFromIcon(icon) || label;
  const badgeIcon = renderAtlaskitIcon(icon, testId) || renderImageIcon(url, testId, ui === null || ui === void 0 ? void 0 : ui.hideLoadingSkeleton);
  if (!formattedMessageOrLabel || !badgeIcon) {
    return null;
  }
  if (iconSize === 'large' && fg('platform_sl_3p_auth_rovo_action_kill_switch')) {
    var _context$actions;
    // eslint-disable-next-line react-hooks/rules-of-hooks
    const context = useFlexibleUiContext();
    if (context !== null && context !== void 0 && (_context$actions = context.actions) !== null && _context$actions !== void 0 && _context$actions[InternalActionName.RovoChatAction]) {
      return /*#__PURE__*/React.createElement("span", {
        "data-smart-element": name,
        "data-smart-element-badge": true,
        "data-testid": testId,
        ref: ref,
        style: {
          color
        },
        className: ax([styles.containerLarge, colorMap[appearance]])
      }, !hideIcon && /*#__PURE__*/React.createElement(Box, {
        as: "span",
        testId: `${testId}-large-icon-wrapper`,
        xcss: styles.icon && styles.iconLarge
      }, badgeIcon), /*#__PURE__*/React.createElement(Box, {
        as: "span",
        testId: `${testId}-label`,
        xcss: styles.text
      }, formattedMessageOrLabel));
    }
  }
  return /*#__PURE__*/React.createElement("span", {
    "data-smart-element": name,
    "data-smart-element-badge": true,
    "data-testid": testId,
    ref: ref,
    style: {
      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: `${testId}-label`,
    xcss: styles.text
  }, formattedMessageOrLabel));
});
export default withOverrideCss(BaseBadgeRefreshNew);
export const toBadgeProps = label => {
  // Don't render the element if its 0
  return label !== '0' && label ? {
    label
  } : undefined;
};