function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
import React from 'react';
var CompactWrapper = function CompactWrapper(_ref) {
  var children = _ref.children,
    _ref$targetsBaseClass = _ref.targetsBaseClass,
    targetsBaseClass = _ref$targetsBaseClass === void 0 ? {} : _ref$targetsBaseClass;
  // 转换子元素为数组
  var childrenArray = React.Children.toArray(children);

  // 处理后的子元素
  var newChildren = childrenArray.map(function (child, index) {
    var _child$type, _child$props$classNam;
    var baseClass = targetsBaseClass[child === null || child === void 0 || (_child$type = child.type) === null || _child$type === void 0 ? void 0 : _child$type.componentName];
    if (!baseClass) return child;

    // 获取当前元素的类名数组
    var existingClasses = ((_child$props$classNam = child.props.className) === null || _child$props$classNam === void 0 ? void 0 : _child$props$classNam.split(/\s+/)) || [];
    var additionalClasses = [];

    // 添加基础紧凑样式
    additionalClasses.push("".concat(baseClass, "-compact-item"));

    // 判断位置（仅在直接子元素层级）
    var isFirst = index === 0;
    var isLast = index === childrenArray.length - 1;

    // 添加首尾样式
    if (isFirst) additionalClasses.push("".concat(baseClass, "-compact-first-item"));
    if (isLast) additionalClasses.push("".concat(baseClass, "-compact-last-item"));

    // 合并类名并去重
    var mergedClassName = [].concat(_toConsumableArray(existingClasses), additionalClasses).filter(Boolean).join(' ') || undefined;

    // 仅克隆当前元素，不处理子元素的子元素
    return /*#__PURE__*/React.cloneElement(child, {
      className: mergedClassName
    });
  });
  return /*#__PURE__*/React.createElement(React.Fragment, null, newChildren);
};
export default CompactWrapper;