import { __rest } from "tslib";
import { jsx as _jsx } from "react/jsx-runtime";
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';

const Grid = _a => {
  var {
    children,
    className,
    style
  } = _a,
      props = __rest(_a, ["children", "className", "style"]);

  const {
    prefixCls,
    createNamespace
  } = useContext(ConfigProviderContext);
  const [bem] = createNamespace('grid', prefixCls);
  return _jsx("div", Object.assign({
    style: Object.assign({
      paddingLeft: addUnit(props.gutter)
    }, style),
    className: cls(className, bem(), {
      [BORDER_TOP]: props.border && !props.gutter
    })
  }, {
    children: React.Children.toArray(children).filter(Boolean).map((child, index) => React.cloneElement(child, {
      index,
      parent: props
    }))
  }));
};

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