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

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); }

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, { useContext } from 'react';
import cls from 'clsx';
import { addUnit } from '../utils';
import { BORDER_TOP } from '../utils/constant';
import ConfigProviderContext from '../config-provider/ConfigProviderContext';

var Grid = function Grid(_ref) {
  var _cls;

  var children = _ref.children,
      className = _ref.className,
      style = _ref.style,
      props = _objectWithoutPropertiesLoose(_ref, _excluded);

  var _useContext = useContext(ConfigProviderContext),
      prefixCls = _useContext.prefixCls,
      createNamespace = _useContext.createNamespace;

  var _createNamespace = createNamespace('grid', prefixCls),
      bem = _createNamespace[0];

  return /*#__PURE__*/React.createElement("div", {
    style: _extends({
      paddingLeft: addUnit(props.gutter)
    }, style),
    className: cls(className, bem(), (_cls = {}, _cls[BORDER_TOP] = props.border && !props.gutter, _cls))
  }, React.Children.toArray(children).filter(Boolean).map(function (child, index) {
    return /*#__PURE__*/React.cloneElement(child, {
      index: index,
      parent: props
    });
  }));
};

Grid.defaultProps = {
  center: true,
  border: true,
  columnNum: 4
};
export default Grid;