"use strict";

var _typeof3 = require("@babel/runtime-corejs3/helpers/typeof");

var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");

var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");

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

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

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

var _extends3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));

var _typeof2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/typeof"));

var _getOwnPropertySymbols = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols"));

var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));

var React = _interopRequireWildcard(require("react"));

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

var _RowContext = _interopRequireDefault(require("./RowContext"));

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

function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof3(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

var __rest = void 0 && (void 0).__rest || function (s, e) {
  var t = {};

  for (var p in s) {
    if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
  }

  if (s != null && typeof _getOwnPropertySymbols["default"] === "function") for (var i = 0, p = (0, _getOwnPropertySymbols["default"])(s); i < p.length; i++) {
    if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
  }
  return t;
};

function parseFlex(flex) {
  if (typeof flex === 'number') {
    var _context;

    return (0, _concat["default"])(_context = "".concat(flex, " ")).call(_context, flex, " auto");
  }

  if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex)) {
    return "0 0 ".concat(flex);
  }

  return flex;
}

var Col = /*#__PURE__*/React.forwardRef(function (props, ref) {
  var renderCol = function renderCol(_ref) {
    var _context12, _context13, _context14, _context15, _context16, _classNames;

    var getPrefixCls = _ref.getPrefixCls,
        direction = _ref.direction;

    var customizePrefixCls = props.prefixCls,
        span = props.span,
        order = props.order,
        offset = props.offset,
        push = props.push,
        pull = props.pull,
        className = props.className,
        children = props.children,
        flex = props.flex,
        style = props.style,
        others = __rest(props, ["prefixCls", "span", "order", "offset", "push", "pull", "className", "children", "flex", "style"]);

    var prefixCls = getPrefixCls('col', customizePrefixCls);
    var sizeClassObj = {};
    ['xs', 'sm', 'md', 'lg', 'xl', 'xxl'].forEach(function (size) {
      var _context2, _context3, _context4, _context5, _context6, _context7, _context8, _context9, _context10, _context11, _extends2;

      var sizeProps = {};
      var propSize = props[size];

      if (typeof propSize === 'number') {
        sizeProps.span = propSize;
      } else if ((0, _typeof2["default"])(propSize) === 'object') {
        sizeProps = propSize || {};
      }

      delete others[size];
      sizeClassObj = (0, _extends3["default"])((0, _extends3["default"])({}, sizeClassObj), (_extends2 = {}, (0, _defineProperty2["default"])(_extends2, (0, _concat["default"])(_context2 = (0, _concat["default"])(_context3 = "".concat(prefixCls, "-")).call(_context3, size, "-")).call(_context2, sizeProps.span), sizeProps.span !== undefined), (0, _defineProperty2["default"])(_extends2, (0, _concat["default"])(_context4 = (0, _concat["default"])(_context5 = "".concat(prefixCls, "-")).call(_context5, size, "-order-")).call(_context4, sizeProps.order), sizeProps.order || sizeProps.order === 0), (0, _defineProperty2["default"])(_extends2, (0, _concat["default"])(_context6 = (0, _concat["default"])(_context7 = "".concat(prefixCls, "-")).call(_context7, size, "-offset-")).call(_context6, sizeProps.offset), sizeProps.offset || sizeProps.offset === 0), (0, _defineProperty2["default"])(_extends2, (0, _concat["default"])(_context8 = (0, _concat["default"])(_context9 = "".concat(prefixCls, "-")).call(_context9, size, "-push-")).call(_context8, sizeProps.push), sizeProps.push || sizeProps.push === 0), (0, _defineProperty2["default"])(_extends2, (0, _concat["default"])(_context10 = (0, _concat["default"])(_context11 = "".concat(prefixCls, "-")).call(_context11, size, "-pull-")).call(_context10, sizeProps.pull), sizeProps.pull || sizeProps.pull === 0), (0, _defineProperty2["default"])(_extends2, "".concat(prefixCls, "-rtl"), direction === 'rtl'), _extends2));
    });
    var classes = (0, _classnames["default"])(prefixCls, (_classNames = {}, (0, _defineProperty2["default"])(_classNames, (0, _concat["default"])(_context12 = "".concat(prefixCls, "-")).call(_context12, span), span !== undefined), (0, _defineProperty2["default"])(_classNames, (0, _concat["default"])(_context13 = "".concat(prefixCls, "-order-")).call(_context13, order), order), (0, _defineProperty2["default"])(_classNames, (0, _concat["default"])(_context14 = "".concat(prefixCls, "-offset-")).call(_context14, offset), offset), (0, _defineProperty2["default"])(_classNames, (0, _concat["default"])(_context15 = "".concat(prefixCls, "-push-")).call(_context15, push), push), (0, _defineProperty2["default"])(_classNames, (0, _concat["default"])(_context16 = "".concat(prefixCls, "-pull-")).call(_context16, pull), pull), _classNames), className, sizeClassObj);
    return /*#__PURE__*/React.createElement(_RowContext["default"].Consumer, null, function (_ref2) {
      var gutter = _ref2.gutter;
      var mergedStyle = (0, _extends3["default"])({}, style);

      if (gutter) {
        mergedStyle = (0, _extends3["default"])((0, _extends3["default"])((0, _extends3["default"])({}, gutter[0] > 0 ? {
          paddingLeft: gutter[0] / 2,
          paddingRight: gutter[0] / 2
        } : {}), gutter[1] > 0 ? {
          paddingTop: gutter[1] / 2,
          paddingBottom: gutter[1] / 2
        } : {}), mergedStyle);
      }

      if (flex) {
        mergedStyle.flex = parseFlex(flex);
      }

      return /*#__PURE__*/React.createElement("div", (0, _extends3["default"])({}, others, {
        style: mergedStyle,
        className: classes,
        ref: ref
      }), children);
    });
  };

  return /*#__PURE__*/React.createElement(_configProvider.ConfigConsumer, null, renderCol);
});
Col.displayName = 'Col';
var _default = Col;
exports["default"] = _default;