import PropTypes from 'prop-types'
import { isEmpty } from 'ramda'
import React from 'react'
import MTIcon from './mt-icon'

const MTButton = React.forwardRef((props, ref) => {
  const {
    disabled,
    label,
    color,
    size,
    icon,
    className,
    type,
    ...otherProps
  } = props

  const buttonIcon = isEmpty(icon)
    ? null
    : <MTIcon align={ true } type={ icon } />

  const buttonLabel = isEmpty(label)
    ? null
    : <span className="mt-button__label">{ label }</span>

  return (
    <button
      // eslint-disable-next-line react/button-has-type
      type={ type }
      className={ `button button--${color} button--${size} ${className}` }
      disabled={ disabled }
      ref={ ref }
      { ...otherProps }
    >
      { buttonIcon }
      { buttonLabel }
    </button>
  )
})

MTButton.defaultProps = {
  disabled: false,
  color: 'white',
  size: 'normal',
  icon: '',
  className: '',
  label: '',
  type: 'button',
}

MTButton.propTypes = {
  disabled: PropTypes.bool,
  color: PropTypes.string,
  label: PropTypes.string,
  size: PropTypes.string,
  icon: PropTypes.string,
  className: PropTypes.string,
  type: PropTypes.string,
}

export default MTButton
