/**
 * Created by Marlon on 7/8/2015.
 */
var EmailPreview = React.createClass({
    getInitialState: function () {
        $(EmailTemplateEntity).on('EmailTemplatesHasChanged', function () {
            this.setState({messages: emailTemplatesInfo})
        }.bind(this));
        return ({messages: emailTemplatesInfo});
    },
    render: function () {
        messages = this.state.messages;
        var i = 0;
        var count = this.state.messages.length;
        return (
            <div data-role="page" id="adminEmail" className="container">
                <div className="page-header">
                    <h1>Sent {count} Emails
                    </h1>
                </div>

                <table className="table table-bordered selection pointer">
                    <tbody>
                    <tr>
                        <td>
                            {
                                $.map(messages, function (message) {
                                    return ([<div key={i++}
                                        className={message.result == 0 ? "alert alert-danger" : "alert alert-success"}
                                        role="alert">{message.email} {message.result == 0 ? "Failed to send" : "Was Successful"}</div>]);
                                })
                            }
                        </td>
                    </tr>
                    </tbody>
                </table>
            </div>
        );

    }

});