"use strict";

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

var _typeof = require("@babel/runtime/helpers/typeof");

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

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

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

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

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

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

var _constants = require("../../constants");

var _theme = _interopRequireDefault(require("./theme.css"));

var _excluded = ["alignContent", "alignItems", "alignSelf", "backgroundColor", "backgroundTint", "borderBottomWidth", "borderColor", "borderLeftWidth", "borderRightWidth", "borderTint", "borderTopWidth", "borderWidth", "borderRadius", "borderTopLeftRadius", "borderTopRightRadius", "borderBottomLeftRadius", "borderBottomRightRadius", "boxSizing", "children", "className", "display", "element", "flex", "flexBasis", "flexDirection", "flexGrow", "flexShrink", "flexWrap", "justifyContent", "margin", "marginHorizontal", "marginVertical", "marginBottom", "marginLeft", "marginRight", "marginTop", "order", "overflow", "overflowX", "overflowY", "padding", "paddingHorizontal", "paddingVertical", "paddingBottom", "paddingLeft", "paddingRight", "paddingTop", "style", "textAlign"];

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 || _typeof(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; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }

var margins = [-8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8];
var paddings = [0, 1, 2, 3, 4, 5, 6, 7, 8];
var borderRadiuses = {
  square: null,
  circle: '50%',
  rounded: '4px'
};
var Box = /*#__PURE__*/(0, _react.forwardRef)(function (_ref, ref) {
  var _cx;

  var alignContent = _ref.alignContent,
      alignItems = _ref.alignItems,
      alignSelf = _ref.alignSelf,
      backgroundColor = _ref.backgroundColor,
      backgroundTint = _ref.backgroundTint,
      borderBottomWidth = _ref.borderBottomWidth,
      _ref$borderColor = _ref.borderColor,
      borderColor = _ref$borderColor === void 0 ? 'neutral' : _ref$borderColor,
      borderLeftWidth = _ref.borderLeftWidth,
      borderRightWidth = _ref.borderRightWidth,
      _ref$borderTint = _ref.borderTint,
      borderTint = _ref$borderTint === void 0 ? 'dark' : _ref$borderTint,
      borderTopWidth = _ref.borderTopWidth,
      borderWidth = _ref.borderWidth,
      _ref$borderRadius = _ref.borderRadius,
      borderRadius = _ref$borderRadius === void 0 ? 'square' : _ref$borderRadius,
      _ref$borderTopLeftRad = _ref.borderTopLeftRadius,
      borderTopLeftRadius = _ref$borderTopLeftRad === void 0 ? borderRadius : _ref$borderTopLeftRad,
      _ref$borderTopRightRa = _ref.borderTopRightRadius,
      borderTopRightRadius = _ref$borderTopRightRa === void 0 ? borderRadius : _ref$borderTopRightRa,
      _ref$borderBottomLeft = _ref.borderBottomLeftRadius,
      borderBottomLeftRadius = _ref$borderBottomLeft === void 0 ? borderRadius : _ref$borderBottomLeft,
      _ref$borderBottomRigh = _ref.borderBottomRightRadius,
      borderBottomRightRadius = _ref$borderBottomRigh === void 0 ? borderRadius : _ref$borderBottomRigh,
      boxSizing = _ref.boxSizing,
      children = _ref.children,
      className = _ref.className,
      display = _ref.display,
      _ref$element = _ref.element,
      element = _ref$element === void 0 ? 'div' : _ref$element,
      flex = _ref.flex,
      flexBasis = _ref.flexBasis,
      flexDirection = _ref.flexDirection,
      flexGrow = _ref.flexGrow,
      flexShrink = _ref.flexShrink,
      flexWrap = _ref.flexWrap,
      justifyContent = _ref.justifyContent,
      _ref$margin = _ref.margin,
      margin = _ref$margin === void 0 ? 0 : _ref$margin,
      _ref$marginHorizontal = _ref.marginHorizontal,
      marginHorizontal = _ref$marginHorizontal === void 0 ? margin : _ref$marginHorizontal,
      _ref$marginVertical = _ref.marginVertical,
      marginVertical = _ref$marginVertical === void 0 ? margin : _ref$marginVertical,
      _ref$marginBottom = _ref.marginBottom,
      marginBottom = _ref$marginBottom === void 0 ? marginVertical : _ref$marginBottom,
      _ref$marginLeft = _ref.marginLeft,
      marginLeft = _ref$marginLeft === void 0 ? marginHorizontal : _ref$marginLeft,
      _ref$marginRight = _ref.marginRight,
      marginRight = _ref$marginRight === void 0 ? marginHorizontal : _ref$marginRight,
      _ref$marginTop = _ref.marginTop,
      marginTop = _ref$marginTop === void 0 ? marginVertical : _ref$marginTop,
      order = _ref.order,
      overflow = _ref.overflow,
      overflowX = _ref.overflowX,
      overflowY = _ref.overflowY,
      _ref$padding = _ref.padding,
      padding = _ref$padding === void 0 ? 0 : _ref$padding,
      _ref$paddingHorizonta = _ref.paddingHorizontal,
      paddingHorizontal = _ref$paddingHorizonta === void 0 ? padding : _ref$paddingHorizonta,
      _ref$paddingVertical = _ref.paddingVertical,
      paddingVertical = _ref$paddingVertical === void 0 ? padding : _ref$paddingVertical,
      _ref$paddingBottom = _ref.paddingBottom,
      paddingBottom = _ref$paddingBottom === void 0 ? paddingVertical : _ref$paddingBottom,
      _ref$paddingLeft = _ref.paddingLeft,
      paddingLeft = _ref$paddingLeft === void 0 ? paddingHorizontal : _ref$paddingLeft,
      _ref$paddingRight = _ref.paddingRight,
      paddingRight = _ref$paddingRight === void 0 ? paddingHorizontal : _ref$paddingRight,
      _ref$paddingTop = _ref.paddingTop,
      paddingTop = _ref$paddingTop === void 0 ? paddingVertical : _ref$paddingTop,
      style = _ref.style,
      textAlign = _ref.textAlign,
      others = (0, _objectWithoutProperties2.default)(_ref, _excluded);

  var getBorder = function getBorder(value) {
    return "".concat(value, "px solid ").concat(_constants.COLOR[borderColor.toUpperCase()][borderTint.toUpperCase()]);
  };

  var classNames = (0, _classnames.default)(_theme.default['box'], (_cx = {}, (0, _defineProperty2.default)(_cx, _theme.default["align-content-".concat(alignContent)], alignContent), (0, _defineProperty2.default)(_cx, _theme.default["align-items-".concat(alignItems)], alignItems), (0, _defineProperty2.default)(_cx, _theme.default["align-self-".concat(alignSelf)], alignSelf), (0, _defineProperty2.default)(_cx, _theme.default["background-color-".concat(backgroundColor, "-").concat(backgroundTint)], backgroundColor && backgroundTint), (0, _defineProperty2.default)(_cx, _theme.default["background-color-".concat(backgroundColor)], backgroundColor && (!backgroundTint || backgroundTint === 'normal')), (0, _defineProperty2.default)(_cx, _theme.default["display-".concat(display)], display), (0, _defineProperty2.default)(_cx, _theme.default["flex-direction-".concat(flexDirection)], flexDirection), (0, _defineProperty2.default)(_cx, _theme.default["flex-wrap-".concat(flexWrap)], flexWrap), (0, _defineProperty2.default)(_cx, _theme.default["justify-content-".concat(justifyContent)], justifyContent), (0, _defineProperty2.default)(_cx, _theme.default["margin-bottom-".concat(marginBottom)], marginBottom > 0), (0, _defineProperty2.default)(_cx, _theme.default["margin-left-".concat(marginLeft)], marginLeft > 0), (0, _defineProperty2.default)(_cx, _theme.default["margin-right-".concat(marginRight)], marginRight > 0), (0, _defineProperty2.default)(_cx, _theme.default["margin-top-".concat(marginTop)], marginTop > 0), (0, _defineProperty2.default)(_cx, _theme.default["margin-bottom-negative-".concat(Math.abs(marginBottom))], marginBottom < 0), (0, _defineProperty2.default)(_cx, _theme.default["margin-left-negative-".concat(Math.abs(marginLeft))], marginLeft < 0), (0, _defineProperty2.default)(_cx, _theme.default["margin-right-negative-".concat(Math.abs(marginRight))], marginRight < 0), (0, _defineProperty2.default)(_cx, _theme.default["margin-top-negative-".concat(Math.abs(marginTop))], marginTop < 0), (0, _defineProperty2.default)(_cx, _theme.default["padding-bottom-".concat(paddingBottom)], paddingBottom > 0), (0, _defineProperty2.default)(_cx, _theme.default["padding-left-".concat(paddingLeft)], paddingLeft > 0), (0, _defineProperty2.default)(_cx, _theme.default["padding-right-".concat(paddingRight)], paddingRight > 0), (0, _defineProperty2.default)(_cx, _theme.default["padding-top-".concat(paddingTop)], paddingTop > 0), (0, _defineProperty2.default)(_cx, _theme.default["text-align-".concat(textAlign)], textAlign), _cx), className);

  var elementStyles = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, borderWidth && {
    border: getBorder(borderWidth)
  }), borderBottomWidth && {
    borderBottom: getBorder(borderBottomWidth)
  }), borderLeftWidth && {
    borderLeft: getBorder(borderLeftWidth)
  }), borderRightWidth && {
    borderRight: getBorder(borderRightWidth)
  }), borderTopWidth && {
    borderTop: getBorder(borderTopWidth)
  }), borderRadius && {
    borderRadius: borderRadiuses[borderRadius]
  }), borderTopLeftRadius && {
    borderTopLeftRadius: borderRadiuses[borderTopLeftRadius]
  }), borderTopRightRadius && {
    borderTopRightRadius: borderRadiuses[borderTopRightRadius]
  }), borderBottomLeftRadius && {
    borderBottomLeftRadius: borderRadiuses[borderBottomLeftRadius]
  }), borderBottomRightRadius && {
    borderBottomRightRadius: borderRadiuses[borderBottomRightRadius]
  }), boxSizing && {
    boxSizing: boxSizing
  }), flex && {
    flex: flex
  }), flexBasis && {
    flexBasis: flexBasis
  }), typeof flexGrow === 'number' && !isNaN(flexGrow) ? {
    flexGrow: flexGrow
  } : {}), typeof flexShrink === 'number' && !isNaN(flexShrink) ? {
    flexShrink: flexShrink
  } : {}), typeof order === 'number' && !isNaN(order) ? {
    order: order
  } : {}), overflow && {
    overflow: overflow
  }), overflowX && {
    overflowX: overflowX
  }), overflowY && {
    overflowY: overflowY
  }), style);

  var Element = element;
  return /*#__PURE__*/_react.default.createElement(Element, (0, _extends2.default)({
    className: classNames,
    ref: ref,
    style: elementStyles
  }, others), children);
});
Box.displayName = 'Box';
var _default = Box;
exports.default = _default;