import { defineComponent, computed, createVNode, mergeProps } from 'vue';
import Popover from '../popover/index.mjs';
import { cloneElement } from '../_util/vnode.mjs';
import { getPropsSlot, flattenChildren } from '../_util/props-util/index.mjs';
import '../hooks/index.mjs';
import Avatar from './Avatar.mjs';
import useStyle from './style/index.mjs';
import { useProviderSize } from './SizeContext.mjs';
import useConfigInject from '../config-provider/hooks/useConfigInject.mjs';

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__ */ defineComponent({
  compatConfig: {
    MODE: 3
  },
  name: "AAvatarGroup",
  inheritAttrs: false,
  props: groupProps(),
  setup(props, {
    slots,
    attrs
  }) {
    const {
      prefixCls,
      direction
    } = useConfigInject("avatar", props);
    const groupPrefixCls = computed(() => `${prefixCls.value}-group`);
    const [wrapSSR, hashId] = useStyle(prefixCls);
    useProviderSize(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 = getPropsSlot(slots, props);
      const childrenWithProps = flattenChildren(children).map((child, index) => 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(createVNode(Popover, {
          "key": "avatar-popover-key",
          "content": childrenHidden,
          "trigger": maxPopoverTrigger,
          "placement": maxPopoverPlacement,
          "overlayClassName": `${groupPrefixCls.value}-popover`
        }, {
          default: () => [createVNode(Avatar, {
            "style": maxStyle
          }, {
            default: () => [`+${numOfChildren - maxCount}`]
          })]
        }));
        return wrapSSR(createVNode("div", mergeProps(attrs, {
          "class": cls,
          "style": attrs.style
        }), [childrenShow]));
      }
      return wrapSSR(createVNode("div", mergeProps(attrs, {
        "class": cls,
        "style": attrs.style
      }), [childrenWithProps]));
    };
  }
});

export { Group as default, groupProps };
//# sourceMappingURL=Group.mjs.map
