import React__default, { forwardRef, useContext, Fragment } from "react";
import cs from "../_util/classNames.js";
import { ConfigContext } from "../ConfigProvider/index.js";
import { isArray, isNumber } from "../_util/is.js";
import useMergeProps from "../_util/hooks/useMergeProps.js";
import { jsx, jsxs } from "../../../../../../@emotion_react@11.10.4_3toe27fv7etiytxb5kxc7fxaw4/node_modules/@emotion/react/jsx-runtime/dist/emotion-react-jsx-runtime.browser.esm.js";
var __assign = globalThis && globalThis.__assign || function() {
  __assign = Object.assign || function(t) {
    for (var s, i = 1, n = arguments.length; i < n; i++) {
      s = arguments[i];
      for (var p in s)
        if (Object.prototype.hasOwnProperty.call(s, p))
          t[p] = s[p];
    }
    return t;
  };
  return __assign.apply(this, arguments);
};
var __rest = globalThis && globalThis.__rest || function(s, e) {
  var t = {};
  for (var p in s)
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
      t[p] = s[p];
  if (s != null && typeof Object.getOwnPropertySymbols === "function")
    for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
      if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
        t[p[i]] = s[p[i]];
    }
  return t;
};
var defaultProps = {
  size: "small",
  direction: "horizontal"
};
function Space(baseProps, ref) {
  var _a;
  var _b = useContext(ConfigContext), getPrefixCls = _b.getPrefixCls, componentConfig = _b.componentConfig, rtl = _b.rtl;
  var props = useMergeProps(baseProps, defaultProps, componentConfig === null || componentConfig === void 0 ? void 0 : componentConfig.Space);
  var className = props.className, style = props.style, children = props.children, size = props.size, direction = props.direction, align = props.align, wrap = props.wrap, split = props.split, rest = __rest(props, ["className", "style", "children", "size", "direction", "align", "wrap", "split"]);
  var prefixCls = getPrefixCls("space");
  var innerAlign = align || (direction === "horizontal" ? "center" : "");
  var classNames = cs(prefixCls, (_a = {}, _a[prefixCls + "-" + direction] = direction, _a[prefixCls + "-align-" + innerAlign] = innerAlign, _a[prefixCls + "-wrap"] = wrap, _a[prefixCls + "-rtl"] = rtl, _a), className);
  function getMargin(size2) {
    if (isNumber(size2)) {
      return size2;
    }
    switch (size2) {
      case "mini":
        return 4;
      case "small":
        return 8;
      case "medium":
        return 16;
      case "large":
        return 24;
      default:
        return 8;
    }
  }
  var childrenList = React__default.Children.toArray(children);
  function getMarginStyle(index) {
    var _a2, _b2, _c, _d;
    var isLastOne = childrenList.length === index + 1;
    var marginDirection = rtl ? "marginLeft" : "marginRight";
    if (typeof size === "string" || typeof size === "number") {
      var margin = getMargin(size);
      if (wrap) {
        return isLastOne ? {
          marginBottom: margin
        } : (_a2 = {}, _a2["" + marginDirection] = margin, _a2.marginBottom = margin, _a2);
      }
      return !isLastOne ? (_b2 = {}, _b2[direction === "vertical" ? "marginBottom" : marginDirection] = margin, _b2) : {};
    }
    if (isArray(size)) {
      var marginHorizontal = getMargin(size[0]);
      var marginBottom = getMargin(size[1]);
      if (wrap) {
        return isLastOne ? {
          marginBottom
        } : (_c = {}, _c["" + marginDirection] = marginHorizontal, _c.marginBottom = marginBottom, _c);
      }
      if (direction === "vertical") {
        return {
          marginBottom
        };
      }
      return _d = {}, _d["" + marginDirection] = marginHorizontal, _d;
    }
  }
  return /* @__PURE__ */ jsx("div", {
    ...__assign({
      ref,
      className: classNames,
      style
    }, rest),
    children: childrenList.map(function(child, index) {
      var _a2;
      var key = ((_a2 = child) === null || _a2 === void 0 ? void 0 : _a2.key) || index;
      var shouldRenderSplit = split !== void 0 && split !== null && index > 0;
      return /* @__PURE__ */ jsxs(Fragment, {
        children: [shouldRenderSplit && /* @__PURE__ */ jsx("div", {
          className: prefixCls + "-item-split",
          children: split
        }), /* @__PURE__ */ jsx("div", {
          className: prefixCls + "-item",
          style: getMarginStyle(index),
          children: child
        })]
      }, key);
    })
  });
}
var SpaceComponent = forwardRef(Space);
SpaceComponent.displayName = "Space";
const Space$1 = SpaceComponent;
export {
  Space$1 as default
};
//# sourceMappingURL=index.js.map
