'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _styledComponents = require('styled-components');

var _styledComponents2 = _interopRequireDefault(_styledComponents);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _themeGet = require('../../extensions/themeGet');

var _themeGet2 = _interopRequireDefault(_themeGet);

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

var normalize = function normalize(size) {
  if (!size) {
    return 'large';
  }

  switch (size) {
    case 'xs':
    case 'extraSmall':
      return 'extraSmall';
    case 'sm':
    case 'small':
      return 'small';
    case 'lg':
    case 'large':
      return 'large';
    case 'xl':
    case 'extraLarge':
      return 'extraLarge';
    case 'md':
    case 'medium':
      return 'medium';
    default:
      return size;
  }
};

var getSpacing = function getSpacing(props, size) {
  try {
    return (0, _themeGet2.default)('spacing.' + normalize(size))(props);
  } catch (err) {
    return size;
  }
};

var Spacing = _styledComponents2.default.div.withConfig({
  displayName: 'Spacing'
})(['', ' ', ' ', ' ', ' ', ';'], function (props) {
  return 'padding: ' + getSpacing(props, props.size) + ';';
}, function (props) {
  return props.top ? 'padding-top: ' + getSpacing(props, props.top) + ';' : '';
}, function (props) {
  return props.bottom ? 'padding-bottom: ' + getSpacing(props, props.bottom) + ';' : '';
}, function (props) {
  return props.left ? 'padding-left: ' + getSpacing(props, props.left) + ';' : '';
}, function (props) {
  return props.right ? 'padding-right: ' + getSpacing(props, props.right) + ';' : '';
});

Spacing.propTypes = {
  /**
   * The default size to be applied to all directions. [xs, sm, md, lg, xl] or a CSS dimension.
   */
  size: _propTypes2.default.string,
  /**
   * The top spacing size. [xs, sm, md, lg, xl] or a CSS dimension.
   */
  top: _propTypes2.default.string,
  /**
   * The bottom spacing size. [xs, sm, md, lg, xl] or a CSS dimension.
   */
  bottom: _propTypes2.default.string,
  /**
   * The left spacing size. [xs, sm, md, lg, xl] or a CSS dimension.
   */
  left: _propTypes2.default.string,
  /**
   * The right spacing size. [xs, sm, md, lg, xl] or a CSS dimension.
   */
  right: _propTypes2.default.string,
  /**
   * Adds a class name to the element.
   */
  className: _propTypes2.default.string,
  /**
   * Adds an id to the element.
   */
  id: _propTypes2.default.string
};

Spacing.defaultProps = {
  size: 'lg',
  top: null,
  bottom: null,
  left: null,
  right: null,
  className: null,
  id: null
};

/**
 * @component
 */
exports.default = Spacing;