'use strict';

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

var _extends = Object.assign || 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; };

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

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

var _styledComponents2 = _interopRequireDefault(_styledComponents);

var _polished = require('polished');

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

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var BaseButton = _styledComponents2.default.button.attrs({
  type: function type(props) {
    return props.type ? props.type : 'button';
  }
}).withConfig({
  displayName: 'Button__BaseButton'
})(['display:flex;flex-direction:row;justify-content:center;align-items:center;width:', ';min-width:', ';height:', ';padding:', ';margin:', ';box-sizing:border-box;user-select:none;text-align:center;text-decoration:none;vertical-align:middle;letter-spacing:normal;transition:all .2s ease-in-out;white-space:nowrap;line-height:1;text-transform:', ';font-family:\'Montserrat\',Helvetica,sans-serif;font-size:14px;font-weight:', ';cursor:', ';opacity:', ';color:', ';background-color:', ';border-radius:', ';border-style:solid;border-width:', ';border-color:', ';opacity:', ';&:hover{border-color:', ';background-color:', ';}&:focus{outline:0;}'], function (props) {
  return props.fullwidth ? '100%' : props.width ? props.width : 'auto';
}, function (props) {
  return props.width ? props.width : '140px';
}, function (props) {
  return props.height;
}, function (props) {
  return props.padding ? props.padding : '10px 15px';
}, function (props) {
  return props.margin;
}, function (props) {
  return props.uppercase ? 'uppercase' : props.capitalize ? 'capitalize' : 'none';
}, function (props) {
  return props.bold ? '700' : '300';
}, function (props) {
  return props.disabled ? 'not-allowed' : 'pointer';
}, function (props) {
  return props.disabled ? 0.5 : 1;
}, function (props) {
  return props.theme[props.color];
}, function (props) {
  return props.theme[props.backgroundColor];
}, function (props) {
  return props.rounded ? '20px' : '3px';
}, function (props) {
  return props.rounded ? '2px' : '1px';
}, function (props) {
  return props.theme[props.borderColor];
}, function (props) {
  return props.disabled ? 0.5 : 1;
}, function (props) {
  return props.disabled ? 'none' : (0, _polished.darken)(0.1, props.theme[props.borderColor]);
}, function (props) {
  return props.disabled ? 'none' : (0, _polished.darken)(0.1, props.theme[props.backgroundColor]);
});

var selectColor = function selectColor(nature, disabled) {
  if (disabled) {
    return { color: 'white', backgroundColor: 'brand-secondary', borderColor: 'brand-secondary' };
  }

  switch (nature) {
    case 'empty':
      return { color: 'gray-6', backgroundColor: 'white', borderColor: 'gray-2' };
    case 'light':
      return { color: 'brand-secondary', backgroundColor: 'white', borderColor: 'brand-secondary' };
    case 'primary':
      return { color: 'white', backgroundColor: 'brand-secondary', borderColor: 'brand-secondary' };
    case 'secondary':
      return { color: 'white', backgroundColor: 'brand-primary', borderColor: 'brand-primary' };
    case 'copy':
      return { color: 'white', backgroundColor: 'success', borderColor: 'success' };
    case 'received':
      return { color: 'white', backgroundColor: 'received', borderColor: 'received' };
    case 'sent':
      return { color: 'white', backgroundColor: 'sent', borderColor: 'sent' };
    case 'transferred':
      return { color: 'white', backgroundColor: 'transferred', borderColor: 'transferred' };
    case 'logout':
      return { color: 'white', backgroundColor: 'error', borderColor: 'error' };
    case 'dark':
      return { color: 'white', backgroundColor: 'gray-6', borderColor: 'gray-6' };
    case 'empty-secondary':
      return { color: 'white', backgroundColor: 'white', borderColor: 'brand-secondary' };
    default:
      return { color: 'gray-6', backgroundColor: 'white', borderColor: 'gray-2' };
  }
};

var Button = function Button(props) {
  var children = props.children,
      nature = props.nature,
      disabled = props.disabled,
      rest = _objectWithoutProperties(props, ['children', 'nature', 'disabled']);

  var _selectColor = selectColor(nature, disabled),
      color = _selectColor.color,
      backgroundColor = _selectColor.backgroundColor,
      borderColor = _selectColor.borderColor;

  return _react2.default.createElement(
    BaseButton,
    _extends({}, rest, {
      disabled: disabled,
      color: color,
      backgroundColor: backgroundColor,
      borderColor: borderColor }),
    children
  );
};

Button.propTypes = {
  nature: _propTypes2.default.oneOf(['empty', 'light', 'primary', 'secondary', 'copy', 'received', 'sent', 'transferred', 'logout', 'dark', 'empty-secondary']),
  fullwidth: _propTypes2.default.bool,
  disabled: _propTypes2.default.bool,
  rounded: _propTypes2.default.bool,
  bold: _propTypes2.default.bool,
  uppercase: _propTypes2.default.bool,
  capitalize: _propTypes2.default.bool,
  width: _propTypes2.default.string,
  padding: _propTypes2.default.string,
  margin: _propTypes2.default.string
};

Button.defaultProps = {
  nature: 'empty',
  fullwidth: false,
  disabled: false,
  rounded: false,
  bold: false,
  uppercase: false,
  capitalize: false,
  height: '40px'
};

exports.default = Button;