"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _react = _interopRequireWildcard(require("react"));

var _mobxReactLite = require("mobx-react-lite");

var _isNil = _interopRequireDefault(require("lodash/isNil"));

var _noop = _interopRequireDefault(require("lodash/noop"));

function getCount(count) {
  if (typeof count === 'function') {
    return count();
  }

  return count;
}

function defaultRenderer(props) {
  var text = props.text;

  if (text) {
    return text;
  }
}

var Count = function Count(props) {
  var count = props.count,
      overflowCount = props.overflowCount,
      prefixCls = props.prefixCls,
      _props$renderer = props.renderer,
      renderer = _props$renderer === void 0 ? defaultRenderer : _props$renderer,
      _props$asyncCount = props.asyncCount,
      asyncCount = _props$asyncCount === void 0 ? _noop["default"] : _props$asyncCount;
  var number = getCount(count);
  (0, _react.useEffect)(function () {
    if (count !== number) {
      asyncCount();
    }
  }, [number]);
  var renderedText = renderer({
    text: overflowCount && number && number > overflowCount ? "".concat(overflowCount, "+") : number,
    count: number,
    overflowCount: overflowCount
  });

  if (!(0, _isNil["default"])(renderedText)) {
    return /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefixCls, "-tab-count")
    }, renderedText);
  }

  return null;
};

Count.displayName = 'Count';

var _default = (0, _mobxReactLite.observer)(Count);

exports["default"] = _default;
//# sourceMappingURL=Count.js.map
