"use strict";

function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.Box = void 0;
var _react = _interopRequireDefault(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _utils = require("../../common/utils");
var _excluded = ["as", "backgroundColor", "children", "m", "mb", "ml", "mr", "mt", "mx", "my", "p", "pb", "pl", "pr", "pt", "px", "py", "lg", "md", "sm", "xl", "className"];
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
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 isPropPresentedIn = function isPropPresentedIn(props) {
  return function (prop) {
    return typeof props[prop] !== 'undefined';
  };
};
var getCssString = function getCssString(property, value) {
  if ((0, _utils.isString)(value)) {
    return (0, _styledComponents.css)(["", ":", ";"], property, value);
  }
  if ((0, _utils.isNumber)(value)) {
    return (0, _styledComponents.css)(["", ":", "px;"], property, function (p) {
      return p.theme.spacing.unit(value);
    });
  }
  return '';
};
var getStyles = function getStyles(props) {
  var _spacings$margins, _spacings$paddings;
  var left = 0;
  var top = 1;
  var right = 2;
  var bottom = 3;
  var DIRECTION = {
    0: 'left',
    1: 'top',
    2: 'right',
    3: 'bottom'
  };
  var spacings = {
    margin: undefined,
    padding: undefined,
    margins: [undefined, undefined, undefined, undefined],
    paddings: [undefined, undefined, undefined, undefined]
  };
  var isPropPresented = isPropPresentedIn(props);
  if (isPropPresented('m')) spacings.margin = props.m;
  if (isPropPresented('mx')) {
    spacings.margins[right] = props.mx;
    spacings.margins[left] = props.mx;
  }
  if (isPropPresented('my')) {
    spacings.margins[top] = props.my;
    spacings.margins[bottom] = props.my;
  }
  if (isPropPresented('mt')) spacings.margins[top] = props.mt;
  if (isPropPresented('mb')) spacings.margins[bottom] = props.mb;
  if (isPropPresented('ml')) spacings.margins[left] = props.ml;
  if (isPropPresented('mr')) spacings.margins[right] = props.mr;
  if (isPropPresented('p')) spacings.padding = props.p;
  if (isPropPresented('px')) {
    spacings.paddings[right] = props.px;
    spacings.paddings[left] = props.px;
  }
  if (isPropPresented('py')) {
    spacings.paddings[top] = props.py;
    spacings.paddings[bottom] = props.py;
  }
  if (isPropPresented('pt')) spacings.paddings[top] = props.pt;
  if (isPropPresented('pb')) spacings.paddings[bottom] = props.pb;
  if (isPropPresented('pl')) spacings.paddings[left] = props.pl;
  if (isPropPresented('pr')) spacings.paddings[right] = props.pr;
  var marginsStyles = (_spacings$margins = spacings.margins) === null || _spacings$margins === void 0 ? void 0 : _spacings$margins.map(function (v, idx) {
    return v !== undefined && getCssString("margin-".concat(DIRECTION[idx]), v);
  });
  var paddingsStyles = (_spacings$paddings = spacings.paddings) === null || _spacings$paddings === void 0 ? void 0 : _spacings$paddings.map(function (v, idx) {
    return v !== undefined && getCssString("padding-".concat(DIRECTION[idx]), v);
  });
  var marginStyles = [spacings.margin && getCssString('margin', spacings.margin)];
  var paddingStyles = [spacings.padding && getCssString('padding', spacings.padding)];
  return marginStyles.concat(marginsStyles).concat(paddingStyles).concat(paddingsStyles).filter(Boolean);
};
var getStylesForSize = function getStylesForSize(size) {
  return (0, _styledComponents.css)(["", "{", "}"], function (p) {
    return p.theme.media.greaterThan(p.theme.breakpoints[size]);
  }, function (p) {
    return getStyles(p[size]);
  });
};
var getColor = function getColor(props) {
  var backgroundColor = props.backgroundColor,
    theme = props.theme;
  if (backgroundColor && typeof backgroundColor === 'function') {
    return backgroundColor(theme);
  }
  if (backgroundColor === 'inherit') {
    return 'inherit';
  }
  return 'transparent';
};
var StyledDiv = _styledComponents.default.div.withConfig({
  displayName: "Box__StyledDiv",
  componentId: "sc-1bfv3i9-0"
})(["", " ", " ", " ", " ", " background-color:", ";"], function (p) {
  return getStyles(p);
}, function (p) {
  return p.sm ? getStylesForSize('sm') : '';
}, function (p) {
  return p.md ? getStylesForSize('md') : '';
}, function (p) {
  return p.xl ? getStylesForSize('xl') : '';
}, function (p) {
  return p.lg ? getStylesForSize('lg') : '';
}, function (p) {
  return getColor(p);
});
var Box = exports.Box = _react.default.forwardRef(function (_ref, ref) {
  var as = _ref.as,
    backgroundColor = _ref.backgroundColor,
    children = _ref.children,
    m = _ref.m,
    mb = _ref.mb,
    ml = _ref.ml,
    mr = _ref.mr,
    mt = _ref.mt,
    mx = _ref.mx,
    my = _ref.my,
    p = _ref.p,
    pb = _ref.pb,
    pl = _ref.pl,
    pr = _ref.pr,
    pt = _ref.pt,
    px = _ref.px,
    py = _ref.py,
    lg = _ref.lg,
    md = _ref.md,
    sm = _ref.sm,
    xl = _ref.xl,
    className = _ref.className,
    rest = _objectWithoutProperties(_ref, _excluded);
  return _react.default.createElement(StyledDiv, _extends({
    ref: ref
  }, _objectSpread({
    as: as,
    backgroundColor: backgroundColor,
    children: children,
    m: m,
    mb: mb,
    ml: ml,
    mr: mr,
    mt: mt,
    mx: mx,
    my: my,
    p: p,
    pb: pb,
    pl: pl,
    pr: pr,
    pt: pt,
    px: px,
    py: py,
    lg: lg,
    md: md,
    sm: sm,
    xl: xl,
    className: className
  }, rest)));
});