import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
import _createClass from "@babel/runtime/helpers/createClass";
import _inherits from "@babel/runtime/helpers/inherits";
import _createSuper from "@babel/runtime/helpers/createSuper";
import * as React from 'react';
import classNames from 'classnames';
import toArray from "rc-util/es/Children/toArray";
import Popover from '../popover';
import { cloneElement } from '../_util/reactNode';
import ConfigContext from '../config-provider/ConfigContext';
import { Size } from '../_util/enum';
import { AvatarContextProvider } from './AvatarContext';

var Group = /*#__PURE__*/function (_React$Component) {
  _inherits(Group, _React$Component);

  var _super = _createSuper(Group);

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

    return _super.apply(this, arguments);
  }

  _createClass(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 = classNames(prefixCls, className);
      var childrenWithProps = toArray(children).map(function (child, index) {
        return 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 = classNames(numberCls, (_classNames = {}, _defineProperty(_classNames, "".concat(numberCls, "-lg"), size === Size.large), _defineProperty(_classNames, "".concat(numberCls, "-sm"), size === Size.small), _classNames));
        var additionNumber = Math.min(numOfChildren - maxCount, 99);
        childrenShow.push( /*#__PURE__*/React.createElement(Popover, {
          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(AvatarContextProvider, {
          size: size,
          getPrefixCls: getPrefixCls
        }, /*#__PURE__*/React.createElement("div", {
          className: cls,
          style: style
        }, childrenShow));
      }

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

  return Group;
}(React.Component);

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