function _extends() { _extends = Object.assign || 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); }

import React from 'react';
import { Box, HStack, VStack } from '../../primitives';
// const isDebug = process.env.NODE_ENV !== 'production';
const DEBUG_STYLES = false ? {
  rows: {
    border: '1px solid black'
  },
  cols: {
    border: '1px solid red'
  }
} : {
  rows: {},
  cols: {}
};
export function SimpleGrid({
  columns,
  spacing,
  spacingX,
  spacingY,
  minChildWidth,
  children
}) {
  let cellSpacing = spacing !== null && spacing !== void 0 ? spacing : 0;
  let cellSpacingX = spacingX !== null && spacingX !== void 0 ? spacingX : cellSpacing;
  let cellSpacingY = spacingY !== null && spacingY !== void 0 ? spacingY : cellSpacing;
  const childrenArray = React.Children.toArray(children);

  if (columns) {
    let rowSlices = [];

    for (let i = 0; i < childrenArray.length; i = i + columns) {
      rowSlices.push(childrenArray.slice(i, i + columns));
    }

    return /*#__PURE__*/React.createElement(VStack, _extends({}, DEBUG_STYLES.rows, {
      space: cellSpacingY
    }), rowSlices.map((row, rowIndex) => {
      return /*#__PURE__*/React.createElement(HStack, {
        space: cellSpacingX,
        key: rowIndex
      }, row.map(col => {
        return /*#__PURE__*/React.createElement(Box, _extends({}, DEBUG_STYLES.cols, {
          key: col.key
        }), col);
      }));
    }));
  } // Needs more work for empty spacing i.e. auto-fit. Current workaround is to use wrap and let the columns be created dynamically
  // https://css-tricks.com/auto-sizing-columns-css-grid-auto-fill-vs-auto-fit/
  else if (minChildWidth) {
      return /*#__PURE__*/React.createElement(Box, {
        flexDirection: "row",
        flexWrap: "wrap",
        justifyContent: "center"
      }, childrenArray.map(col => {
        return /*#__PURE__*/React.createElement(Box, _extends({}, DEBUG_STYLES.cols, {
          mx: cellSpacingX,
          my: cellSpacingY,
          key: col.key,
          minWidth: minChildWidth
        }), col);
      }));
    }

  return /*#__PURE__*/React.createElement(React.Fragment, null);
}
//# sourceMappingURL=SimpleGrid.js.map