"use strict";

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

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

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

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));

var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));

var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));

var _createSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/createSuper"));

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

var _classnames = _interopRequireDefault(require("classnames"));

var _toArray = _interopRequireDefault(require("rc-util/lib/Children/toArray"));

var _popover = _interopRequireDefault(require("../popover"));

var _reactNode = require("../_util/reactNode");

var _ConfigContext = _interopRequireDefault(require("../config-provider/ConfigContext"));

var _enum = require("../_util/enum");

var _AvatarContext = require("./AvatarContext");

var Group = /*#__PURE__*/function (_React$Component) {
  (0, _inherits2["default"])(Group, _React$Component);

  var _super = (0, _createSuper2["default"])(Group);

  function Group() {
    (0, _classCallCheck2["default"])(this, Group);
    return _super.apply(this, arguments);
  }

  (0, _createClass2["default"])(Group, [{
    key: "render",
    value: function render() {
      var _this$props = this.props,
          customizePrefixCls = _this$props.prefixCls,
          className = _this$props.className,
          maxCount = _this$props.maxCount,
          maxStyle = _this$props.maxStyle,
          size = _this$props.size,
          style = _this$props.style,
          children = _this$props.children,
          maxPopoverPlacement = _this$props.maxPopoverPlacement,
          maxPopoverTrigger = _this$props.maxPopoverTrigger;
      var getPrefixCls = this.context.getPrefixCls;
      var prefixCls = getPrefixCls('avatar-group', customizePrefixCls);
      var cls = (0, _classnames["default"])(prefixCls, className);
      var childrenWithProps = (0, _toArray["default"])(children).map(function (child, index) {
        return (0, _reactNode.cloneElement)(child, {
          key: "avatar-key-".concat(index)
        });
      });
      var numOfChildren = childrenWithProps.length;

      if (maxCount && maxCount < numOfChildren) {
        var _classNames;

        var childrenShow = childrenWithProps.slice(0, maxCount);
        var childrenHidden = childrenWithProps.slice(maxCount, numOfChildren);
        var numberCls = "".concat(prefixCls, "-popover-number");
        var popverNumberCls = (0, _classnames["default"])(numberCls, (_classNames = {}, (0, _defineProperty2["default"])(_classNames, "".concat(numberCls, "-lg"), size === _enum.Size.large), (0, _defineProperty2["default"])(_classNames, "".concat(numberCls, "-sm"), size === _enum.Size.small), _classNames));
        var additionNumber = Math.min(numOfChildren - maxCount, 99);
        childrenShow.push( /*#__PURE__*/React.createElement(_popover["default"], {
          key: "avatar-popover-key",
          content: childrenHidden,
          trigger: maxPopoverTrigger,
          placement: maxPopoverPlacement,
          overlayClassName: "".concat(prefixCls, "-popover")
        }, /*#__PURE__*/React.createElement("span", {
          className: "".concat(prefixCls, "-popover-mask")
        }, childrenHidden[0], /*#__PURE__*/React.createElement("span", {
          style: maxStyle,
          "data-contentlength": "+".concat(additionNumber).length,
          className: popverNumberCls
        }, "+", additionNumber))));
        return /*#__PURE__*/React.createElement(_AvatarContext.AvatarContextProvider, {
          size: size,
          getPrefixCls: getPrefixCls
        }, /*#__PURE__*/React.createElement("div", {
          className: cls,
          style: style
        }, childrenShow));
      }

      return /*#__PURE__*/React.createElement(_AvatarContext.AvatarContextProvider, {
        size: size,
        getPrefixCls: getPrefixCls
      }, /*#__PURE__*/React.createElement("div", {
        className: cls,
        style: style
      }, childrenWithProps));
    }
  }], [{
    key: "contextType",
    get: function get() {
      return _ConfigContext["default"];
    }
  }]);
  return Group;
}(React.Component);

exports["default"] = Group;
Group.displayName = 'AvatarGroup';
Group.defaultProps = {
  size: _enum.Size["default"],
  maxPopoverPlacement: 'top',
  maxPopoverTrigger: 'hover',
  className: ''
};
//# sourceMappingURL=Group.js.map
