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

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

app.state.Profile = function()
{
    var state = app.core.StateManager.createState( 'profile' );

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

        app.gui.PageLoader.show();

        app.core.Rpc.call(
            'Profile',
            'get',
            {
                profileId : profileId
            },
            function( res )
            {
                app.core.View.setContent(
                    app.core.View.getTemplate(
                        'profile',
                        {
                            p : new app.model.Profile( res.profile, res.profile_teams ),
                            currentUser : app.model.SessionUser.getUserProfile()
                        }
                    )
                );

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

    return state;
};