'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 _reactLoader = require('react-loader');

var _reactLoader2 = _interopRequireDefault(_reactLoader);

var _style = require('./style.scss');

var _style2 = _interopRequireDefault(_style);

var _bind = require('classnames/bind');

var _bind2 = _interopRequireDefault(_bind);

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

var Button = function Button(props) {
  var cx = _bind2.default.bind(_style2.default);
  var loaderClasses = props.loading ? 'loading' : null;
  var btnClasses = cx(_style2.default.btn, props.optClass, props.size, loaderClasses);
  var spinnerOptions = {
    lines: 10,
    length: 4,
    width: 3,
    radius: 5
  };

  return _react2.default.createElement(
    'button',
    _extends({ type: 'button', className: btnClasses, disabled: props.disabled || props.loading }, props),
    props.loading ? _react2.default.createElement(_reactLoader2.default, { loaded: false, options: spinnerOptions }) : null,
    _react2.default.createElement(
      'em',
      null,
      props.children
    )
  );
};

Button.propTypes = {
  /**
   * Optional styles to add to the button.
   */
  optClass: _react2.default.PropTypes.string,
  /**
   * The size of button.
   */
  size: _react2.default.PropTypes.string,
  /**
   * Whether the button is disabled.
   */
  disabled: _react2.default.PropTypes.bool,
  /**
   * Whether the loading spinner is displayed.
   */
  loading: _react2.default.PropTypes.bool
};

exports.default = Button;