import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
var _excluded = ["children", "className", "color", "direction", "size"];

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

import React, { forwardRef, isValidElement } from 'react';
import PropTypes from 'prop-types';
import Box, { pickBoxProps } from '../box';
/** @type {React.ComponentType<any>} */

var IslandGroup = /*#__PURE__*/forwardRef(function (_ref, ref) {
  var originalChildren = _ref.children,
      className = _ref.className,
      color = _ref.color,
      direction = _ref.direction,
      size = _ref.size,
      otherProps = _objectWithoutProperties(_ref, _excluded);

  var boxProps = pickBoxProps(otherProps);
  var children = [];
  React.Children.forEach(originalChildren, function (child) {
    if ( /*#__PURE__*/isValidElement(child)) {
      children.push(child);
    }
  });
  var hasMoreThanOneChild = children.length > 1;
  return /*#__PURE__*/React.createElement(Box, _extends({
    ref: ref
  }, boxProps, {
    className: className,
    display: "flex",
    flexDirection: direction === 'horizontal' ? 'row' : 'column'
  }), React.Children.map(children, function (child, index) {
    var isFirstChild = index === 0;
    var isLastChild = index === children.length - 1;
    return /*#__PURE__*/React.cloneElement(child, _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, !isFirstChild && !isLastChild && {
      borderRadius: 'square'
    }), direction === 'horizontal' && !isFirstChild && {
      borderLeftWidth: 0
    }), direction === 'horizontal' && hasMoreThanOneChild && isFirstChild && {
      borderBottomRightRadius: 'square',
      borderTopRightRadius: 'square'
    }), direction === 'horizontal' && hasMoreThanOneChild && isLastChild && {
      borderBottomLeftRadius: 'square',
      borderTopLeftRadius: 'square'
    }), direction === 'vertical' && !isFirstChild && {
      borderTopWidth: 0
    }), direction === 'vertical' && hasMoreThanOneChild && isFirstChild && {
      borderBottomLeftRadius: 'square',
      borderBottomRightRadius: 'square'
    }), direction === 'vertical' && hasMoreThanOneChild && isLastChild && {
      borderTopLeftRadius: 'square',
      borderTopRightRadius: 'square'
    }), child.props), {}, {
      color: color || child.props.color,
      size: size || child.props.size
    }));
  }));
});
IslandGroup.displayName = 'IslandGroup';
IslandGroup.defaultProps = {
  direction: 'horizontal'
};
export default IslandGroup;