'use strict';

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

var vue = require('vue');
require('../../../utils/index.cjs');
var index$1 = require('../../popover/index.cjs');
var useConfigInject = require('../../config-provider/src/hooks/useConfigInject.cjs');
var index = require('../style/index.cjs');
var Avatar = require('./Avatar.cjs');
var AvatarContext = require('./AvatarContext.cjs');
var props = require('./props.cjs');
var props$1 = require('../../../utils/vue/props.cjs');
var vnode = require('../../../utils/vue/vnode.cjs');

var AAvatarGroup = /* @__PURE__ */ vue.defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AAvatarGroup",
  inheritAttrs: false,
  props: 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);
    vue.watchEffect(() => {
      const context = {
        size: props.size,
        shape: props.shape
      };
      AvatarContext.useAvatarProviderContext(context);
    });
    return () => {
      const {
        maxPopoverPlacement = "top",
        maxCount,
        maxStyle,
        maxPopoverTrigger = "hover",
        shape
      } = props;
      const cls = {
        [groupPrefixCls.value]: true,
        [`${groupPrefixCls.value}-rtl`]: direction.value === "rtl",
        [`${attrs.class}`]: !!attrs.class,
        [hashId.value]: true
      };
      const children = props$1.getPropsSlot(slots, props);
      const childrenWithProps = props$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$1.Popover, {
          "key": "avatar-popover-key",
          "content": childrenHidden,
          "trigger": maxPopoverTrigger,
          "placement": maxPopoverPlacement,
          "overlayClassName": `${groupPrefixCls.value}-popover`
        }, {
          default: () => [vue.createVNode(Avatar.default, {
            "style": maxStyle,
            "shape": shape
          }, {
            default: () => [`+${numOfChildren - maxCount}`]
          })]
        }));
        return wrapSSR(vue.createVNode("div", {
          ...attrs,
          "class": cls,
          "style": attrs.style
        }, [childrenShow]));
      }
      return wrapSSR(vue.createVNode("div", {
        ...attrs,
        "class": cls,
        "style": attrs.style
      }, [childrenWithProps]));
    };
  }
});

exports.default = AAvatarGroup;
//# sourceMappingURL=Group.cjs.map
