const CoronaSpecial = {
    route : 'corona/special/:groupId',
    isDefault : true,
    templateUrl : 'js/app/views/corona/corona-special.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 = [],
              apps = [],
              self = this,
              app = this.app,
              groupId = p.get( 'groupId' );

        this.render();

        app.rpc.call(
            'Team',
            'getDetails',
            {
                teamId : 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 = self.createInstance( 'UserProfile', res.data.members[ mi ] );
                        m.setContextGroupId( groupId );
                        members.push( m );
                    }

                    app.rpc.call(
                        'Appointment',
                        'getList',
                        {
                            groupId : groupId,
                            filter : 'all'
                        },
                        function( res2 )
                        {
                            if ( res2 && res2.hasOwnProperty( 'data' ) && res2.data.hasOwnProperty( 'appointments' ) )
                            {
                                let app;
                                for ( let ai = 0; ai < res2.data.appointments.length; ai++ )
                                {
                                    app = self.createInstance( 'Appointment', res2.data.appointments[ ai ] );
                                    app.setAttendees( res2.data[ 'attendees_' + res2.data.appointments[ ai ].id ] );
                                    apps.push( app );
                                }
                            }

                            self.createComponent(
                                'corona-tracking',
                                $container.find( '[data-id="container-corona-tracking"]' ).first().get( 0 ),
                                {
                                    members : members,
                                    appointments : apps
                                }
                            );
                            $container.find( '[data-id="ibox-corona-tracking"]' ).toggleClass( 'sk-loading' );
                        }
                    );
                }
            }
        );
    },

    destroy : function()
    {

    }
};

export { CoronaSpecial };