'use strict';

import React from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

const MESSAGE_TYPE_DANGER = 'danger';
const MESSAGE_TYPE_WARNING = 'warning';
const MESSAGE_TYPE_SUCCESS = 'success';
const MESSAGE_TYPE_DEFAULT = 'default';
const MESSAGE_TYPE_MUTED = 'muted';

export class Message extends React.Component {
    static propTypes = {
        children: PropTypes.node.isRequired,
        messageType: PropTypes.oneOf([
            MESSAGE_TYPE_DANGER,
            MESSAGE_TYPE_WARNING,
            MESSAGE_TYPE_SUCCESS,
            MESSAGE_TYPE_DEFAULT,
            MESSAGE_TYPE_MUTED
        ]),
        testAutomationId: PropTypes.string,
        id: PropTypes.string
    };

    static defaultProps = {
        testAutomationId: 'message',
        messageType: MESSAGE_TYPE_DEFAULT,
        id: null
    };

    render() {
        let classNames = classnames({
            'text-danger': this.props.messageType === MESSAGE_TYPE_DANGER,
            'text-warning': this.props.messageType === MESSAGE_TYPE_WARNING,
            'text-success': this.props.messageType === MESSAGE_TYPE_SUCCESS,
            'text-default': this.props.messageType === MESSAGE_TYPE_DEFAULT,
            'text-muted': this.props.messageType === MESSAGE_TYPE_MUTED
        });

        const idProp = this.props.id ? {id: this.props.id} : {};

        return (
            <span
                {...idProp}
                className={classNames}
                data-test-automation-id={this.props.testAutomationId}>
                {this.props.children}
            </span>
        );
    }
}
