"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = void 0;

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));

var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));

var _react = _interopRequireDefault(require("react"));

var _classnames = _interopRequireDefault(require("classnames"));

var _context = _interopRequireDefault(require("./context"));

var _context2 = require("../config-provider/context");

// const responsiveTypes = ['xs', 'md', 'lg', 'xl']
var Col = /*#__PURE__*/_react.default.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 = (0, _objectWithoutProperties2.default)(props, ["className", "children", "prefixCls", "span", "flex", "offset", "style"]);

  var _React$useContext = _react.default.useContext(_context.default),
      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 (0, _objectSpread2.default)((0, _objectSpread2.default)({}, colStyles), style || {});
  };

  var _React$useContext2 = _react.default.useContext(_context2.ConfigContext),
      getPrefixClassName = _React$useContext2.getPrefixClassName;

  var renderDom = function renderDom() {
    var _classNames;

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

  return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, renderDom());
});

Col.defaultProps = {};
var _default = Col;
exports.default = _default;