/**
 * (c) by aheadware.com
 */

var app = app || {};
app.state = app.state || {};

app.state.MessageDetail = function()
{
    var state = app.core.StateManager.createState('message-detail');

    state.onEnter = function (p)
    {
        let $content = app.core.View.getContent(),
            messageId = p.messageId || null;

        app.gui.PageLoader.show();

        app.core.Rpc.call(
            'Message',
            'getDetail',
            {
                messageId : messageId
            },
            function (res)
            {
                var message = new app.model.Message( res.message_data );

                app.core.View.setContent(
                    app.core.View.getTemplate(
                        'message-detail',
                        {
                            message : message
                        })
                );

                $content.find( '[data-id="btn-reply"]' ).first().click( function()
                {
                    app.core.View.toastError( 'Derzeit nicht möglich.' );
                });

                app.gui.PageLoader.hide();
            }
        );
    };

    return state;
};