import React, {PureComponent} from 'react';
import omit from 'lodash.omit';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import {LoadingBalls} from 'display-library/LoadingBalls';

import './button.scss';

class Button extends PureComponent {
  static propTypes = {
    theme: PropTypes.string,
    className: PropTypes.string,
    showLoader: PropTypes.bool,
    onClick: PropTypes.func,
    children: PropTypes.node
  };

  static defaultProps = {
    theme: 'claret'
  };

  render() {
    const {theme, className, showLoader, children} = this.props;

    return (
      <button
        {...omit(this.props, 'theme', 'showLoader', 'children')}
        className={classNames(
          'mo-web-button',
          `mo-web-button--${theme}`,
          className
        )}
      >
        {showLoader ? (
          <LoadingBalls className="mo-web-button-loader" />
        ) : (
          children
        )}
      </button>
    );
  }
}

export default Button;
