var _excluded = ["boxProps", "children", "direction", "size", "space"];
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import React from 'react';
import { Box } from '../Box/Box';
import { StyledFlex } from './FlexList.styles';
function getSingleSize() {
  var size = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  return size.split(' ')[0];
}
function getItemMargin(direction, size) {
  return direction.includes('row') ? "0 ".concat(size) : "".concat(size, " 0");
}
function getMargin(direction, space) {
  var size = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'md';
  if (space === undefined) {
    return {
      margin: getItemMargin(direction, size)
    };
  }
  if (space && direction.includes('row')) {
    return {
      marginRight: space
    };
  }
  if (space && direction.includes('column')) {
    return {
      marginBottom: space
    };
  }
  return {};
}

/**
 * `FlexList` combines `Flex` and `Box`, **each child element is wrapped in a `Box`**
 * having a margin (leading and trailing space removed). This isolates the
 * children React components from the `display: flex` on direct children in CSS.
 */
export var FlexList = /*#__PURE__*/React.forwardRef(function FlexList(_ref, ref) {
  var boxProps = _ref.boxProps,
    children = _ref.children,
    _ref$direction = _ref.direction,
    direction = _ref$direction === void 0 ? 'row' : _ref$direction,
    _ref$size = _ref.size,
    size = _ref$size === void 0 ? 'md' : _ref$size,
    space = _ref.space,
    props = _objectWithoutProperties(_ref, _excluded);
  var singleSize = React.useMemo(function () {
    return getSingleSize(size);
  }, [size]);
  var margin = React.useMemo(function () {
    return getMargin(direction, space, singleSize);
  }, [direction, space, singleSize]);
  return /*#__PURE__*/React.createElement(StyledFlex, _extends({}, props, {
    ref: ref,
    direction: direction,
    $direction: direction
  }), React.Children.toArray(children).filter(function (child) {
    return child;
  }).map(function (child, i) {
    return child && /*#__PURE__*/React.createElement(Box, _extends({}, boxProps, margin, {
      key: child.key || i
    }), child);
  }));
});
FlexList.displayName = 'FlexList';
//# sourceMappingURL=FlexList.js.map