var _excluded = ["children", "maxLength", "ellipsis"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React, { forwardRef, useRef, useImperativeHandle } from 'react';

// 数值标
var Badge = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var _ref$children = _ref.children,
    children = _ref$children === void 0 ? '0' : _ref$children,
    _ref$maxLength = _ref.maxLength,
    maxLength = _ref$maxLength === void 0 ? 2 : _ref$maxLength,
    _ref$ellipsis = _ref.ellipsis,
    ellipsis = _ref$ellipsis === void 0 ? '+' : _ref$ellipsis,
    props = _objectWithoutProperties(_ref, _excluded);
  // 节点
  var rootRef = useRef(null);
  useImperativeHandle(ref, function () {
    return {
      rootDOM: rootRef.current,
      getRootDOM: function getRootDOM() {
        return rootRef.current;
      }
    };
  });

  // 标题
  var text = children;
  if (maxLength && children && (typeof children === 'string' || typeof children === 'number')) {
    text = text.toString();
    // 数字大于99,则显示99+
    if (!isNaN(text)) {
      text = text.length > maxLength ? '99999'.substring(0, maxLength) + ellipsis : text;
    } else {
      text = text.length > maxLength ? text.substring(0, maxLength) + ellipsis : text;
    }
  }
  return /*#__PURE__*/React.createElement("span", _extends({}, props, {
    className: "badge".concat(props.className ? ' ' + props.className : ''),
    ref: rootRef
  }), text);
});
export default Badge;