"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard")["default"];

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports["default"] = void 0;

var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireWildcard(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _isNil = _interopRequireDefault(require("lodash/isNil"));

var _isFunction = _interopRequireDefault(require("lodash/isFunction"));

var _omit = _interopRequireDefault(require("lodash/omit"));

var _ConfigContext = _interopRequireDefault(require("../../../lib/config-provider/ConfigContext"));

var _isFragment = _interopRequireDefault(require("../_util/isFragment"));

var _enum = require("../field/enum");

var _excluded = ["className", "children", "compact"];

var ItemGroup = function ItemGroup(props) {
  var className = props.className,
      children = props.children,
      compact = props.compact,
      otherProps = (0, _objectWithoutProperties2["default"])(props, _excluded);

  var _useContext = (0, _react.useContext)(_ConfigContext["default"]),
      getProPrefixCls = _useContext.getProPrefixCls;

  var prefixCls = getProPrefixCls('form-item-group');
  var cls = (0, _classnames["default"])(className, prefixCls, (0, _defineProperty2["default"])({}, "".concat(prefixCls, "-compact"), compact));

  var mapChildren = function mapChildren(child) {
    if (! /*#__PURE__*/(0, _react.isValidElement)(child)) {
      return undefined;
    }

    if ((0, _isFragment["default"])(child) && child.props) {
      return _react.Children.map(child.props.children, function (innerChild) {
        return mapChildren(innerChild);
      });
    }

    var itemStyle = {};

    if (child.props && child.props.style && (child.props.style.originalWidth || child.props.style.width)) {
      if (child.props.style.width !== '100%') {
        itemStyle = {
          width: child.props.style.width
        };
        child.props.style.originalWidth = child.props.style.width;
      } else {
        itemStyle = {
          width: child.props.style.originalWidth || child.props.style.width
        };
      }

      child.props.style.width = '100%';
    }

    if (((0, _isFunction["default"])(child.type) || (0, _typeof2["default"])(child.type) === 'object') && child.type.__PRO_FORM_ITEM) {
      return mapChildren(child.props.children);
    }

    var childCls = '';

    if (compact) {
      var suffixCls = child.props.suffixCls;

      var _prefixCls = getProPrefixCls(suffixCls);

      childCls = "".concat(_prefixCls, "-compact");
    }

    return /*#__PURE__*/_react["default"].createElement("span", {
      className: "".concat(prefixCls, "-item ").concat(childCls),
      style: (0, _objectSpread2["default"])({}, itemStyle)
    }, child);
  };

  var childes = _react.Children.map(children, function (child) {
    return mapChildren(child);
  });

  if ((0, _isNil["default"])(childes)) {
    return null;
  }

  var passProps = (0, _omit["default"])(otherProps, ['label', 'labelWidth', 'labelTooltip', 'help', 'showHelp', 'required', 'useColon', 'requiredMarkAlign', 'colSpan', 'rowSpan', 'newLine']);
  return /*#__PURE__*/_react["default"].createElement("span", (0, _extends2["default"])({
    className: cls
  }, passProps), childes);
};

ItemGroup.displayName = 'ItemGroup';
ItemGroup.defaultProps = {
  showHelp: _enum.ShowHelp.label
};
var _default = ItemGroup;
exports["default"] = _default;
//# sourceMappingURL=ItemGroup.js.map
