import * as l from "react";
import h from "../../../classnames/index.mjs";
import Q from "../../../rc-util/es/Children/toArray.mjs";
import { isPresetSize as w, isValidGapNumber as P } from "../_util/gapSize.mjs";
import "../config-provider/index.mjs";
import U from "./Compact.mjs";
import { SpaceContextProvider as X } from "./context.mjs";
import { SpaceContext as ue } from "./context.mjs";
import Y from "./Item.mjs";
import Z from "./style/index.mjs";
import { ConfigContext as ee } from "../config-provider/context.mjs";
var te = globalThis && globalThis.__rest || function(o, n) {
  var i = {};
  for (var t in o)
    Object.prototype.hasOwnProperty.call(o, t) && n.indexOf(t) < 0 && (i[t] = o[t]);
  if (o != null && typeof Object.getOwnPropertySymbols == "function")
    for (var s = 0, t = Object.getOwnPropertySymbols(o); s < t.length; s++)
      n.indexOf(t[s]) < 0 && Object.prototype.propertyIsEnumerable.call(o, t[s]) && (i[t[s]] = o[t[s]]);
  return i;
};
const _ = /* @__PURE__ */ l.forwardRef((o, n) => {
  var i, t;
  const {
    getPrefixCls: s,
    space: e,
    direction: V
  } = l.useContext(ee), {
    size: c = (e == null ? void 0 : e.size) || "small",
    align: S,
    className: E,
    rootClassName: k,
    children: A,
    direction: N = "horizontal",
    prefixCls: I,
    split: G,
    style: H,
    wrap: R = !1,
    classNames: f,
    styles: u
  } = o, T = te(o, ["size", "align", "className", "rootClassName", "children", "direction", "prefixCls", "split", "style", "wrap", "classNames", "styles"]), [m, p] = Array.isArray(c) ? c : [c, c], x = w(p), b = w(m), D = P(p), M = P(m), z = Q(A, {
    keepEmpty: !0
  }), O = S === void 0 && N === "horizontal" ? "center" : S, r = s("space", I), [W, q, B] = Z(r), F = h(r, e == null ? void 0 : e.className, q, `${r}-${N}`, {
    [`${r}-rtl`]: V === "rtl",
    [`${r}-align-${O}`]: O,
    [`${r}-gap-row-${p}`]: x,
    [`${r}-gap-col-${m}`]: b
  }, E, k, B), $ = h(`${r}-item`, (i = f == null ? void 0 : f.item) !== null && i !== void 0 ? i : (t = e == null ? void 0 : e.classNames) === null || t === void 0 ? void 0 : t.item);
  let v = 0;
  const J = z.map((a, y) => {
    var g, C;
    a != null && (v = y);
    const L = a && a.key || `${$}-${y}`;
    return /* @__PURE__ */ l.createElement(Y, {
      className: $,
      key: L,
      index: y,
      split: G,
      style: (g = u == null ? void 0 : u.item) !== null && g !== void 0 ? g : (C = e == null ? void 0 : e.styles) === null || C === void 0 ? void 0 : C.item
    }, a);
  }), K = l.useMemo(() => ({
    latestIndex: v
  }), [v]);
  if (z.length === 0)
    return null;
  const d = {};
  return R && (d.flexWrap = "wrap"), !b && M && (d.columnGap = m), !x && D && (d.rowGap = p), W(/* @__PURE__ */ l.createElement("div", Object.assign({
    ref: n,
    className: F,
    style: Object.assign(Object.assign(Object.assign({}, d), e == null ? void 0 : e.style), H)
  }, T), /* @__PURE__ */ l.createElement(X, {
    value: K
  }, J)));
});
process.env.NODE_ENV !== "production" && (_.displayName = "Space");
const j = _;
j.Compact = U;
const pe = j;
export {
  ue as SpaceContext,
  pe as default
};
