"use strict";

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

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

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

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

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

var DEVICE_SIZES = ["large", "small"];
/** colSize shorthand */

/**
 * @deprecated This component has been deprecated 2021-06-04. Use Grid or LayoutGrid instead.
 */
var Col = _react["default"].forwardRef(function (_ref, ref) {
  var _ref$as = _ref.as,
      Component = _ref$as === void 0 ? "div" : _ref$as,
      border = _ref.border,
      children = _ref.children,
      overflow = _ref.overflow,
      _ref$paddedContent = _ref.paddedContent,
      paddedContent = _ref$paddedContent === void 0 ? "none" : _ref$paddedContent,
      isReadingColumn = _ref.isReadingColumn,
      alignSelf = _ref.alignSelf,
      props = _objectWithoutProperties(_ref, ["as", "border", "children", "overflow", "paddedContent", "isReadingColumn", "alignSelf"]);

  var prefix = "col";
  var spans = [];
  var classes = [];

  if (border) {
    classes.push("border--".concat(border));
  }

  if (overflow) {
    classes.push(overflow);
    classes.push("height--1-1");
  }

  if (paddedContent !== "none") {
    classes.push("padded-content--".concat(paddedContent));
  }

  if (alignSelf) {
    classes.push("align-self-".concat(alignSelf));
  }

  if (isReadingColumn) {
    children = _react["default"].createElement("div", {
      className: "reading-column"
    }, children);
  }

  DEVICE_SIZES.forEach(function (brkPoint) {
    var propValue = props[brkPoint];
    delete props[brkPoint];
    var span;
    var offset;
    var order;

    if (propValue !== null && propValue !== undefined && _typeof(propValue) === "object") {
      var _propValue$span = propValue.span;
      span = _propValue$span === void 0 ? "fillSpace" : _propValue$span;
      offset = propValue.offset;
      order = propValue.order;
    } else {
      span = propValue;
    }

    if (offset !== null && offset !== undefined) {
      classes.push("offset-".concat(brkPoint, "-").concat(offset));
    }

    if (order !== null && order !== undefined) {
      classes.push("order-".concat(brkPoint, "-").concat(order));
    }

    if (span !== null && span !== undefined) {
      spans.push(span === "fillSpace" ? "".concat(prefix, "-").concat(brkPoint) : "".concat(prefix, "-").concat(brkPoint, "-").concat(span));
    }
  });

  if (!spans.length) {
    spans.push(prefix); // plain 'col'
  }

  return _react["default"].createElement(Component, _extends({}, props, {
    ref: ref,
    className: _classnames["default"].apply(void 0, spans.concat(classes))
  }), children);
});

Col.propTypes = {
  as: _propTypes["default"].any,
  border: _propTypes["default"].oneOf(["top", "bottom", "left", "right", "sides", "ends", "all"]),
  children: _propTypes["default"].node.isRequired,
  isReadingColumn: _propTypes["default"].bool,
  large: _propTypes["default"].oneOfType([_propTypes["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].number, _propTypes["default"].oneOf(["fitContent"]), _propTypes["default"].oneOf(["fillSpace"])]), _propTypes["default"].shape({
    border: _propTypes["default"].oneOf(["top", "bottom", "left", "right", "sides", "ends", "all"]).isRequired,
    offset: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired,
    order: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired,
    paddedContent: _propTypes["default"].oneOf(["none", "around", "sides", "ends", "remove"]).isRequired,
    size: _propTypes["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].number, _propTypes["default"].oneOf(["fitContent"]), _propTypes["default"].oneOf(["fillSpace"])]).isRequired
  })]),
  overflow: _propTypes["default"].oneOf(["overflow-y--scroll", "overflow-x--auto", "overflow-y--auto"]),
  paddedContent: _propTypes["default"].oneOf(["around", "sides", "ends", "none", "remove"]),
  ref: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].func, _propTypes["default"].object]),
  small: _propTypes["default"].oneOfType([_propTypes["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].number, _propTypes["default"].oneOf(["fitContent"]), _propTypes["default"].oneOf(["fillSpace"])]), _propTypes["default"].shape({
    border: _propTypes["default"].oneOf(["top", "bottom", "left", "right", "sides", "ends", "all"]).isRequired,
    offset: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired,
    order: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]).isRequired,
    paddedContent: _propTypes["default"].oneOf(["none", "around", "sides", "ends", "remove"]).isRequired,
    size: _propTypes["default"].oneOfType([_propTypes["default"].bool, _propTypes["default"].number, _propTypes["default"].oneOf(["fitContent"]), _propTypes["default"].oneOf(["fillSpace"])]).isRequired
  })]),
  alignSelf: _propTypes["default"].oneOf(["start", "center", "end"])
};
Col.displayName = "Col";
Col.defaultProps = {
  isReadingColumn: false
};
var _default = Col;
exports["default"] = _default;