const MemberList = {
    route : 'members/:groupId',
    isDefault : true,
    templateUrl : 'js/app/views/members/member-list.html',
    navigatioData : null,
    redirectUrl : 'auth/login',

    canAccess : function()
    {
        return this.app.user.isLoggedIn();
    },

    create : function( p )
    {
        this.container = this.app.UI.getContentContainer();
        const $container = $( this.container ),
              members = [];

        this.render();

        this.app.rpc.call(
            'Team',
            'getDetails',
            {
                teamId : p.get( 'groupId' )
            },
            function( res )
            {
                if ( res && res.hasOwnProperty( 'data' ) && res.data.hasOwnProperty( 'members' ) )
                {
                    let m;
                    for ( let mi = 0; mi < res.data.members.length; mi++ )
                    {
                        m = this.createInstance( 'UserProfile', res.data.members[ mi ] );
                        m.setContextGroupId( p.get( 'groupId' ) );
                        members.push( m );
                    }

                    this.createComponent(
                        'member-data-table',
                        $container.find( '[f-id="container-member-data-table"]' ).first().get( 0 ),
                        members
                    );
                }
                $container.find( '.sk-loading' ).toggleClass( 'sk-loading' );
            }.bind ( this )
        );
    },

    destroy : function()
    {

    }
};

export { MemberList };