import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
import React from 'react';
import classNames from 'classnames';
import GridContext from './context';
import { ConfigContext } from '../config-provider/context'; // const responsiveTypes = ['xs', 'md', 'lg', 'xl']

var Col = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var className = props.className,
      children = props.children,
      customPrefixCls = props.prefixCls,
      span = props.span,
      flex = props.flex,
      offset = props.offset,
      style = props.style,
      reset = _objectWithoutProperties(props, ["className", "children", "prefixCls", "span", "flex", "offset", "style"]);

  var _React$useContext = React.useContext(GridContext),
      gutters = _React$useContext.gutters;

  var regUtil = function regUtil(target) {
    return /^\d+(\.\d+)?(px|em|rem|%)$/.test(target);
  };

  var getColStyles = function getColStyles() {
    var colStyles = {};

    if (gutters !== undefined) {
      colStyles.paddingLeft = gutters[0];
      colStyles.paddingRight = gutters[0];

      if (gutters[1]) {
        colStyles.paddingTop = gutters[1];
        colStyles.paddingBottom = gutters[1];
      }
    }

    if (flex !== undefined) {
      if (typeof flex === 'number') {
        colStyles.flex = "".concat(flex, " ").concat(flex, " auto");
      } else if (regUtil(flex)) {
        colStyles.flex = "0 0 ".concat(flex);
      } else {
        colStyles.flex = flex;
      }
    }

    if (offset !== undefined && typeof offset === 'string') {
      if (regUtil(offset)) {
        colStyles.marginLeft = offset;
      }
    }

    return _objectSpread(_objectSpread({}, colStyles), style || {});
  };

  var _React$useContext2 = React.useContext(ConfigContext),
      getPrefixClassName = _React$useContext2.getPrefixClassName;

  var renderDom = function renderDom() {
    var _classNames;

    var prefixCls = getPrefixClassName('col', customPrefixCls);
    var cls = classNames(prefixCls, className, (_classNames = {}, _defineProperty(_classNames, "".concat(prefixCls, "-").concat(span), span), _defineProperty(_classNames, "".concat(prefixCls, "-offset-").concat(offset), typeof offset === 'number'), _classNames));
    return /*#__PURE__*/React.createElement("div", Object.assign({
      style: getColStyles()
    }, reset, {
      className: cls,
      ref: ref
    }), children);
  };

  return /*#__PURE__*/React.createElement(React.Fragment, null, renderDom());
});
Col.defaultProps = {};
export default Col;