import _extends from "@babel/runtime/helpers/extends";
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
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 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) { _defineProperty(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; }

import React, { forwardRef } from 'react';
import cx from 'classnames';
import { COLOR } from '../../constants';
import theme from './theme.css';
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__*/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 = _objectWithoutProperties(_ref, _excluded);

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

  var classNames = cx(theme['box'], (_cx = {}, _defineProperty(_cx, theme["align-content-".concat(alignContent)], alignContent), _defineProperty(_cx, theme["align-items-".concat(alignItems)], alignItems), _defineProperty(_cx, theme["align-self-".concat(alignSelf)], alignSelf), _defineProperty(_cx, theme["background-color-".concat(backgroundColor, "-").concat(backgroundTint)], backgroundColor && backgroundTint), _defineProperty(_cx, theme["background-color-".concat(backgroundColor)], backgroundColor && (!backgroundTint || backgroundTint === 'normal')), _defineProperty(_cx, theme["display-".concat(display)], display), _defineProperty(_cx, theme["flex-direction-".concat(flexDirection)], flexDirection), _defineProperty(_cx, theme["flex-wrap-".concat(flexWrap)], flexWrap), _defineProperty(_cx, theme["justify-content-".concat(justifyContent)], justifyContent), _defineProperty(_cx, theme["margin-bottom-".concat(marginBottom)], marginBottom > 0), _defineProperty(_cx, theme["margin-left-".concat(marginLeft)], marginLeft > 0), _defineProperty(_cx, theme["margin-right-".concat(marginRight)], marginRight > 0), _defineProperty(_cx, theme["margin-top-".concat(marginTop)], marginTop > 0), _defineProperty(_cx, theme["margin-bottom-negative-".concat(Math.abs(marginBottom))], marginBottom < 0), _defineProperty(_cx, theme["margin-left-negative-".concat(Math.abs(marginLeft))], marginLeft < 0), _defineProperty(_cx, theme["margin-right-negative-".concat(Math.abs(marginRight))], marginRight < 0), _defineProperty(_cx, theme["margin-top-negative-".concat(Math.abs(marginTop))], marginTop < 0), _defineProperty(_cx, theme["padding-bottom-".concat(paddingBottom)], paddingBottom > 0), _defineProperty(_cx, theme["padding-left-".concat(paddingLeft)], paddingLeft > 0), _defineProperty(_cx, theme["padding-right-".concat(paddingRight)], paddingRight > 0), _defineProperty(_cx, theme["padding-top-".concat(paddingTop)], paddingTop > 0), _defineProperty(_cx, theme["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.createElement(Element, _extends({
    className: classNames,
    ref: ref,
    style: elementStyles
  }, others), children);
});
Box.displayName = 'Box';
export default Box;