'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var vue = require('vue');
var index$2 = require('../popover/index.js');
var vnode = require('../_util/vnode.js');
var index$1 = require('../_util/props-util/index.js');
require('../hooks/index.js');
var Avatar = require('./Avatar.js');
var index = require('./style/index.js');
var SizeContext = require('./SizeContext.js');
var useConfigInject = require('../config-provider/hooks/useConfigInject.js');

const groupProps = () => ({
  prefixCls: String,
  maxCount: Number,
  maxStyle: {
    type: Object,
    default: void 0
  },
  maxPopoverPlacement: {
    type: String,
    default: "top"
  },
  maxPopoverTrigger: String,
  /*
   * Size of avatar, options: `large`, `small`, `default`
   * or a custom number size
   * */
  size: {
    type: [Number, String, Object],
    default: "default"
  }
});
const Group = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AAvatarGroup",
  inheritAttrs: false,
  props: groupProps(),
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject.default("avatar", props);
    const groupPrefixCls = vue.computed(() => `${prefixCls.value}-group`);
    const [wrapSSR, hashId] = index.default(prefixCls);
    SizeContext.useProviderSize(vue.computed(() => props.size));
    return () => {
      const {
        maxPopoverPlacement = "top",
        maxCount,
        maxStyle,
        maxPopoverTrigger = "hover"
      } = props;
      const cls = {
        [groupPrefixCls.value]: true,
        [`${groupPrefixCls.value}-rtl`]: direction.value === "rtl",
        [`${attrs.class}`]: !!attrs.class,
        [hashId.value]: true
      };
      const children = index$1.getPropsSlot(slots, props);
      const childrenWithProps = index$1.flattenChildren(children).map((child, index) => vnode.cloneElement(child, {
        key: `avatar-key-${index}`
      }));
      const numOfChildren = childrenWithProps.length;
      if (maxCount && maxCount < numOfChildren) {
        const childrenShow = childrenWithProps.slice(0, maxCount);
        const childrenHidden = childrenWithProps.slice(maxCount, numOfChildren);
        childrenShow.push(vue.createVNode(index$2.default, {
          "key": "avatar-popover-key",
          "content": childrenHidden,
          "trigger": maxPopoverTrigger,
          "placement": maxPopoverPlacement,
          "overlayClassName": `${groupPrefixCls.value}-popover`
        }, {
          default: () => [vue.createVNode(Avatar.default, {
            "style": maxStyle
          }, {
            default: () => [`+${numOfChildren - maxCount}`]
          })]
        }));
        return wrapSSR(vue.createVNode("div", vue.mergeProps(attrs, {
          "class": cls,
          "style": attrs.style
        }), [childrenShow]));
      }
      return wrapSSR(vue.createVNode("div", vue.mergeProps(attrs, {
        "class": cls,
        "style": attrs.style
      }), [childrenWithProps]));
    };
  }
});

exports.default = Group;
exports.groupProps = groupProps;
//# sourceMappingURL=Group.js.map
