import React from 'react'
import cx from 'classnames'
import PropTypes from 'prop-types'
import MTIcon from './mt-icon'

function MTMessage (props) {
  const {
    type,
    message,
    icon,
    largeIcon,
    children,
    className,
    ...otherProps
  } = props

  const largeIconClass = largeIcon && 'message--large-icon'
  const messageIcon = icon ? <MTIcon type={ icon } /> : ''
  return (
    <div
      { ...otherProps }
      className={ cx('message', `is-${type}`, largeIconClass, className) }
    >
      <span>{ messageIcon }{ message }</span>
      { children }
    </div>
  )
}

MTMessage.defaultProps = {
  type: 'info',
  largeIcon: false,
}

MTMessage.propTypes = {
  type: PropTypes.oneOf([ 'info', 'warning', 'error', 'success' ]),
  message: PropTypes.string,
  icon: PropTypes.string,
  largeIcon: PropTypes.bool,
  children: PropTypes.node,
}

export default MTMessage
