'use strict';

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

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

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

var _propTypes2 = _interopRequireDefault(_propTypes);

var _formatMoney = require('../../extensions/formatMoney');

var _formatMoney2 = _interopRequireDefault(_formatMoney);

var _MoneyStyles = require('./styles/MoneyStyles');

var _MoneyStyles2 = _interopRequireDefault(_MoneyStyles);

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

var Money = function (_React$Component) {
  (0, _inherits3.default)(Money, _React$Component);

  function Money() {
    (0, _classCallCheck3.default)(this, Money);
    return (0, _possibleConstructorReturn3.default)(this, (Money.__proto__ || (0, _getPrototypeOf2.default)(Money)).apply(this, arguments));
  }

  (0, _createClass3.default)(Money, [{
    key: 'getSign',
    value: function getSign() {
      var value = this.props.value;

      return value >= 0 ? '+' : '-';
    }
  }, {
    key: 'render',
    value: function render() {
      var _props = this.props,
          value = _props.value,
          showSign = _props.showSign,
          id = _props.id,
          className = _props.className,
          Styles = _props.Styles;

      return _react2.default.createElement(
        Styles,
        { value: value, id: id, className: className },
        showSign ? this.getSign(value) : null,
        '$',
        (0, _formatMoney2.default)(value).replace('-', '')
      );
    }
  }]);
  return Money;
}(_react2.default.Component);

Money.propTypes = {
  /**
   * The monetary value to show.
   */
  value: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.number]).isRequired,
  /**
   * Whether or not to show a +/- sign before the amount (defaults true)
   */
  showSign: _propTypes2.default.bool,
  /**
   * Adds a class name to the element.
   */
  className: _propTypes2.default.string,
  /**
   * Adds an id to the element.
   */
  id: _propTypes2.default.string,
  /**
   * A component to render the text itself. Will be passed a `value` Number prop.
   */
  Styles: _propTypes2.default.func
};
Money.defaultProps = {
  showSign: true,
  className: null,
  id: null,
  value: 0,
  Styles: _MoneyStyles2.default
};
exports.default = Money;