"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.renderLozenge = renderLozenge;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _react = _interopRequireDefault(require("react"));
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _inlineLozenge = _interopRequireDefault(require("../common/inline-lozenge"));
var LOZENGE_TEST_ID = 'inline-card-resolved-view-lozenge';
function renderLozenge(lozenge) {
  var _lozenge$style3, _lozenge$style4;
  if (!lozenge || !(lozenge !== null && lozenge !== void 0 && lozenge.text)) {
    return null;
  }
  if ((0, _platformFeatureFlags.fg)('platform-dst-lozenge-tag-badge-visual-uplifts')) {
    var stateMetricMatch = lozenge.text.match(/^(.+?)\s+-\s+(\d+(?:\.\d+)?)$/);
    if (stateMetricMatch) {
      var _lozenge$style, _lozenge$style2;
      var _stateMetricMatch = (0, _slicedToArray2.default)(stateMetricMatch, 3),
        label = _stateMetricMatch[1],
        metric = _stateMetricMatch[2];
      var _appearance = lozenge.appearance || 'neutral';
      return /*#__PURE__*/_react.default.createElement(_inlineLozenge.default, {
        testId: LOZENGE_TEST_ID,
        appearance: _appearance,
        style: {
          backgroundColor: lozenge === null || lozenge === void 0 || (_lozenge$style = lozenge.style) === null || _lozenge$style === void 0 ? void 0 : _lozenge$style.backgroundColor,
          color: lozenge === null || lozenge === void 0 || (_lozenge$style2 = lozenge.style) === null || _lozenge$style2 === void 0 ? void 0 : _lozenge$style2.color
        },
        trailingMetric: metric
      }, label);
    }
  }
  var appearance = lozenge.appearance || 'default';
  return /*#__PURE__*/_react.default.createElement(_inlineLozenge.default, {
    testId: LOZENGE_TEST_ID,
    appearance: appearance,
    style: {
      backgroundColor: lozenge === null || lozenge === void 0 || (_lozenge$style3 = lozenge.style) === null || _lozenge$style3 === void 0 ? void 0 : _lozenge$style3.backgroundColor,
      color: lozenge === null || lozenge === void 0 || (_lozenge$style4 = lozenge.style) === null || _lozenge$style4 === void 0 ? void 0 : _lozenge$style4.color
    },
    isBold: lozenge.isBold !== false
  }, lozenge.text);
}