import v from "../../../classnames/index.mjs";
import P from "../../../rc-util/es/Children/toArray.mjs";
import * as n from "react";
import "../config-provider/index.mjs";
import z from "../config-provider/hooks/useSize.mjs";
import N from "./style/index.mjs";
import { ConfigContext as k } from "../config-provider/context.mjs";
var C = globalThis && globalThis.__rest || function(t, r) {
  var e = {};
  for (var o in t)
    Object.prototype.hasOwnProperty.call(t, o) && r.indexOf(o) < 0 && (e[o] = t[o]);
  if (t != null && typeof Object.getOwnPropertySymbols == "function")
    for (var c = 0, o = Object.getOwnPropertySymbols(t); c < o.length; c++)
      r.indexOf(o[c]) < 0 && Object.prototype.propertyIsEnumerable.call(t, o[c]) && (e[o[c]] = t[o[c]]);
  return e;
};
const p = /* @__PURE__ */ n.createContext(null), T = (t, r) => {
  const e = n.useContext(p), o = n.useMemo(() => {
    if (!e)
      return "";
    const {
      compactDirection: c,
      isFirstItem: u,
      isLastItem: d
    } = e, a = c === "vertical" ? "-vertical-" : "-";
    return v(`${t}-compact${a}item`, {
      [`${t}-compact${a}first-item`]: u,
      [`${t}-compact${a}last-item`]: d,
      [`${t}-compact${a}item-rtl`]: r === "rtl"
    });
  }, [t, r, e]);
  return {
    compactSize: e == null ? void 0 : e.compactSize,
    compactDirection: e == null ? void 0 : e.compactDirection,
    compactItemClassnames: o
  };
}, A = (t) => {
  let {
    children: r
  } = t;
  return /* @__PURE__ */ n.createElement(p.Provider, {
    value: null
  }, r);
}, j = (t) => {
  var {
    children: r
  } = t, e = C(t, ["children"]);
  return /* @__PURE__ */ n.createElement(p.Provider, {
    value: e
  }, r);
}, E = (t) => {
  const {
    getPrefixCls: r,
    direction: e
  } = n.useContext(k), {
    size: o,
    direction: c,
    block: u,
    prefixCls: d,
    className: a,
    rootClassName: y,
    children: x
  } = t, I = C(t, ["size", "direction", "block", "prefixCls", "className", "rootClassName", "children"]), $ = z((m) => o ?? m), i = r("space-compact", d), [b, h] = N(i), g = v(i, h, {
    [`${i}-rtl`]: e === "rtl",
    [`${i}-block`]: u,
    [`${i}-vertical`]: c === "vertical"
  }, a, y), s = n.useContext(p), l = P(x), S = n.useMemo(() => l.map((m, f) => {
    const O = m && m.key || `${i}-item-${f}`;
    return /* @__PURE__ */ n.createElement(j, {
      key: O,
      compactSize: $,
      compactDirection: c,
      isFirstItem: f === 0 && (!s || (s == null ? void 0 : s.isFirstItem)),
      isLastItem: f === l.length - 1 && (!s || (s == null ? void 0 : s.isLastItem))
    }, m);
  }), [o, l, s]);
  return l.length === 0 ? null : b(/* @__PURE__ */ n.createElement("div", Object.assign({
    className: g
  }, I), S));
}, R = E;
export {
  A as NoCompactStyle,
  p as SpaceCompactItemContext,
  R as default,
  T as useCompactItemContext
};
