"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _react = _interopRequireWildcard(require("react"));
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
var _constants = require("../../../../../constants");
var _flexibleUiContext = require("../../../../../state/flexible-ui-context");
var _common = require("../common");
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 STATE_METRIC_REGEX = /^(.+?)\s+-\s+(\d+(?:\.\d+)?)$/;
var StateElement = function StateElement(props) {
  var _context$state;
  var context = (0, _flexibleUiContext.useFlexibleUiContext)();
  var data = (_context$state = context === null || context === void 0 ? void 0 : context.state) !== null && _context$state !== void 0 ? _context$state : null;
  var metricProps = (0, _platformFeatureFlags.fg)('platform-dst-lozenge-tag-badge-visual-uplifts') ?
  // eslint-disable-next-line react-hooks/rules-of-hooks
  (0, _react.useMemo)(function () {
    if (data && typeof data.text === 'string') {
      var match = data.text.match(STATE_METRIC_REGEX);
      if (match) {
        return {
          text: match[1],
          trailingMetric: match[2]
        };
      }
    }
    return null;
  }, [data]) : undefined;
  if (!data) {
    return null;
  }
  return /*#__PURE__*/_react.default.createElement(_common.BaseLozengeElement, (0, _extends2.default)({}, data, props, metricProps, {
    name: _constants.ElementName.State
  }));
};
var _default = exports.default = StateElement;