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

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

app.state.ConfigurationPrivacy = function()
{
    var state = app.core.StateManager.createState( 'configuration-privacy' );

    state.onEnter = function( p )
    {
        let $content = app.core.View.getContent(),
            groups = [],
            profile = null;

        app.gui.PageLoader.show();

        app.core.Rpc.call(
            'Account',
            'getAccountRelatedData',
            null,
            function( res )
            {
                profile = new app.model.Profile( res.profile );

                if ( res.own_teams && res.own_teams.length )
                {
                    for ( var ti = 0; ti < res.own_teams.length; ti++ )
                    {
                        groups.push( new app.model.Group( res.own_teams[ ti ] ) );
                    }
                }

                app.core.View.setContent(
                    app.core.View.getTemplate(
                        'configuration-privacy',
                        {
                            p : profile,
                            groups : groups
                        }
                    )
                );

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

    return state;
};