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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { getColor } from "../../../theme";
var borderMap = {
  all: function all(_ref) {
    var size = _ref.size,
      type = _ref.type,
      color = _ref.color;
    return "\n    border: " + size + " " + type + " " + color + ";\n  ";
  },
  horizontal: function horizontal(_ref2) {
    var size = _ref2.size,
      type = _ref2.type,
      color = _ref2.color;
    return "\n    border-top: " + size + " " + type + " " + color + ";\n    border-bottom: " + size + " " + type + " " + color + ";\n  ";
  },
  vertical: function vertical(_ref3) {
    var size = _ref3.size,
      type = _ref3.type,
      color = _ref3.color;
    return "\n    border-left: " + size + " " + type + " " + color + ";\n    border-right: " + size + " " + type + " " + color + ";\n  ";
  },
  top: function top(_ref4) {
    var size = _ref4.size,
      type = _ref4.type,
      color = _ref4.color;
    return "\n    border-top: " + size + " " + type + " " + color + ";\n  ";
  },
  right: function right(_ref5) {
    var size = _ref5.size,
      type = _ref5.type,
      color = _ref5.color;
    return "\n    border-right: " + size + " " + type + " " + color + ";\n  ";
  },
  bottom: function bottom(_ref6) {
    var size = _ref6.size,
      type = _ref6.type,
      color = _ref6.color;
    return "\n    border-bottom: " + size + " " + type + " " + color + ";\n  ";
  },
  left: function left(_ref7) {
    var size = _ref7.size,
      type = _ref7.type,
      color = _ref7.color;
    return "\n    border-left: " + size + " " + type + " " + color + ";\n  ";
  }
};
var getDefaults = function getDefaults(theme) {
  return {
    color: getColor("border")({
      theme: theme
    }),
    size: "1px",
    side: "all",
    type: "solid"
  };
};
export default (function (_ref8) {
  var theme = _ref8.theme,
    border = _ref8.border;
  if (border === undefined) {
    return "";
  }
  if (border === true) {
    return borderMap.all(getDefaults(theme));
  }
  if (border in borderMap) {
    return borderMap[border](getDefaults(theme));
  }
  if (typeof border === "string" || Array.isArray(border)) {
    return borderMap.all(_objectSpread(_objectSpread({}, getDefaults(theme)), {}, {
      color: getColor(border || "border")({
        theme: theme
      })
    }));
  }
  if (typeof border !== "object") {
    return "";
  }
  var side = border.side,
    color = border.color;
  if (Array.isArray(side)) {
    return side.reduce(function (acc, s) {
      if (s in borderMap) {
        return acc + borderMap[s](_objectSpread(_objectSpread(_objectSpread({}, getDefaults(theme)), border), {}, {
          color: getColor(color || "border")({
            theme: theme
          })
        }));
      }
      return acc;
    }, "");
  }
  return side in borderMap && borderMap[side](_objectSpread(_objectSpread(_objectSpread({}, getDefaults(theme)), border), {}, {
    color: getColor(color || "border")({
      theme: theme
    })
  }));
});