import A from "../../../classnames/index.mjs";
import V from "../../../rc-util/es/Children/toArray.mjs";
import * as e from "react";
import "../config-provider/index.mjs";
import w from "../popover/index.mjs";
import { cloneElement as G } from "../_util/reactNode.mjs";
import I from "./avatar.mjs";
import d from "./AvatarContext.mjs";
import H from "./style/index.mjs";
import M from "../config-provider/hooks/useCSSVarCls.mjs";
import { ConfigContext as O } from "../config-provider/context.mjs";
const y = (t) => {
  const {
    size: o,
    shape: s
  } = e.useContext(d), l = e.useMemo(() => ({
    size: t.size || o,
    shape: t.shape || s
  }), [t.size, t.shape, o, s]);
  return /* @__PURE__ */ e.createElement(d.Provider, {
    value: l
  }, t.children);
}, R = (t) => {
  const {
    getPrefixCls: o,
    direction: s
  } = e.useContext(O), {
    prefixCls: l,
    className: P,
    rootClassName: g,
    style: C,
    maxCount: r,
    maxStyle: z,
    size: h,
    shape: f,
    maxPopoverPlacement: E = "top",
    maxPopoverTrigger: S = "hover",
    children: N
  } = t, m = o("avatar", l), i = `${m}-group`, u = M(m), [v, $, k] = H(m, u), x = A(i, {
    [`${i}-rtl`]: s === "rtl"
  }, k, u, P, g, $), a = V(N).map((n, p) => G(n, {
    key: `avatar-key-${p}`
  })), c = a.length;
  if (r && r < c) {
    const n = a.slice(0, r), p = a.slice(r, c);
    return n.push(/* @__PURE__ */ e.createElement(w, {
      key: "avatar-popover-key",
      content: p,
      trigger: S,
      placement: E,
      overlayClassName: `${i}-popover`
    }, /* @__PURE__ */ e.createElement(I, {
      style: z
    }, `+${c - r}`))), v(/* @__PURE__ */ e.createElement(y, {
      shape: f,
      size: h
    }, /* @__PURE__ */ e.createElement("div", {
      className: x,
      style: C
    }, n)));
  }
  return v(/* @__PURE__ */ e.createElement(y, {
    shape: f,
    size: h
  }, /* @__PURE__ */ e.createElement("div", {
    className: x,
    style: C
  }, a)));
}, L = R;
export {
  L as default
};
