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

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

app.state.AppointmentDetailAttendee = function()
{
    var state = app.core.StateManager.createState( 'appointment-detail-attendee' );

    state.onEnter = function( p )
    {
        let $content = app.core.View.getContent(),
            appointment = null,
            appointmentId = p.id;

        app.gui.PageLoader.show();

        app.core.Rpc.call(
            'Appointment',
            'getDetail',
            {
                appointmentId : appointmentId
            },
            function( res )
            {
                appointment = new app.model.Appointment( res.appointment, res.attendee_data, res.attendee_profiles );

                if ( appointment.isDraft() )
                {
                    app.core.Controller.redirect( '#/home' );
                    return false;
                }

                app.core.View.setContent(
                    app.core.View.getTemplate( 'appointment-detail-attendee', { a: appointment, g : app.model.SessionUser.getGroupById( appointment.getTeamId() ) } )
                );

                $content.on( 'click', '[data-type="profile-link"]', function()
                {
                    app.core.Controller.redirect( '#/profile/' + $(this).attr( 'data-profile-id' ) );
                });

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

    state.onExit = function( p )
    {
    };

    return state;
};