function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _extends() { _extends = Object.assign || 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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }

function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }

function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }

function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }

function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }

function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }

function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import ConfigProvider from '../config-provider';
import { obj } from '../util';
import Sup from './sup';
/**
 * Badge
 */

var Badge =
/*#__PURE__*/
function (_Component) {
  _inherits(Badge, _Component);

  function Badge() {
    _classCallCheck(this, Badge);

    return _possibleConstructorReturn(this, _getPrototypeOf(Badge).apply(this, arguments));
  }

  _createClass(Badge, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          prefix = _this$props.prefix,
          dot = _this$props.dot,
          noTransition = _this$props.noTransition,
          className = _this$props.className,
          children = _this$props.children,
          content = _this$props.content,
          style = _this$props.style,
          rtl = _this$props.rtl,
          originCount = _this$props.count,
          showZero = _this$props.showZero,
          originOverflowCount = _this$props.overflowCount;
      var count = parseInt(originCount, 10);
      var overflowCount = parseInt(originOverflowCount, 10);
      var others = obj.pickOthers(Badge.propTypes, this.props); // 如果是数字，则添加默认的 title

      if (count || count === 0 && showZero) {
        others.title = others.title || "".concat(count);
      }

      var classes = classNames("".concat(prefix, "badge"), _defineProperty({}, "".concat(prefix, "badge-not-a-wrapper"), !children), className);
      return React.createElement("span", _extends({
        dir: rtl ? 'rtl' : undefined,
        className: classes
      }, others), children, React.createElement(Sup, {
        prefix: prefix,
        content: content,
        count: count,
        showZero: showZero,
        overflowCount: overflowCount,
        dot: dot,
        noTransition: noTransition,
        style: style
      }));
    }
  }]);

  return Badge;
}(Component);

_defineProperty(Badge, "propTypes", {
  // 样式类名的品牌前缀
  prefix: PropTypes.string,
  rtl: PropTypes.bool,
  // 自定义类名
  className: PropTypes.string,
  // 自定义内联样式
  style: PropTypes.object,

  /**
   * 徽章依托的内容
   */
  children: PropTypes.node,

  /**
   * 展示的数字，大于 overflowCount 时显示为 ${overflowCount}+，为 0 时默认隐藏
   */
  count: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

  /**
   * 当count为0时，是否显示count
   */
  showZero: PropTypes.bool,

  /**
   * 自定义节点内容
   */
  content: PropTypes.node,

  /**
   * 展示的封顶的数字
   */
  overflowCount: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),

  /**
   * 不展示数字，只展示一个小红点
   */
  dot: PropTypes.bool,

  /**
   * 不展示数字切换时的动画
   */
  noTransition: PropTypes.bool
});

_defineProperty(Badge, "defaultProps", {
  prefix: 'next-',
  count: 0,
  showZero: false,
  overflowCount: 99,
  dot: false,
  noTransition: false
});

export default ConfigProvider.config(Badge);