"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

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

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

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

var _propTypes = _interopRequireDefault(require("prop-types"));

var _ramda = require("ramda");

var _mapResponsiveProperty = _interopRequireDefault(require("../utils/mapResponsiveProperty"));

var Types = _interopRequireWildcard(require("../types"));

var _Box = _interopRequireDefault(require("../Box"));

var _useTheme2 = _interopRequireDefault(require("../hooks/useTheme"));

var spanToWidth = function spanToWidth(maxColumns) {
  return function (columnSpan) {
    return columnSpan / maxColumns;
  };
};

var Col = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var span = _ref.span,
      maxColumnsProp = _ref.maxColumns,
      rest = (0, _objectWithoutProperties2["default"])(_ref, ["span", "maxColumns"]);

  var _useTheme = (0, _useTheme2["default"])(),
      _useTheme$grid = _useTheme.grid;

  _useTheme$grid = _useTheme$grid === void 0 ? {} : _useTheme$grid;
  var gutters = _useTheme$grid.gutters,
      maxColumns = _useTheme$grid.maxColumns;
  return /*#__PURE__*/_react["default"].createElement(_Box["default"], (0, _extends2["default"])({
    ref: ref,
    px: gutters,
    width: (0, _mapResponsiveProperty["default"])(spanToWidth((0, _ramda.isNil)(maxColumnsProp) ? maxColumns : maxColumnsProp), span)
  }, rest));
});
Col.displayName = 'Col';
process.env.NODE_ENV !== "production" ? Col.propTypes = {
  maxColumns: _propTypes["default"].number,
  span: Types.responsiveNumber
} : void 0;
var _default = Col;
exports["default"] = _default;