<% var data = this.stash; %>
<% var currentUser = app.model.SessionUser.getUserProfile(); %>
<% var groupsOwner = currentUser.getGroupsByRole( 'trainer' ), groupDataOwner = groupsOwner.length >= 1 ? groupsOwner[ 0 ] : null; %>
<% if ( 0 === appointments.length ) {   %>

    <h4>
        <%= _lc( 'NO_APPOINTMENTS_AVAILABLE' ) %>
        <span class="float-right clickable" style="margin-right: 12px">
            <div data-type="btn-filter"
                 class="<%= ( false === filter.isModified ) ? 'text-primary' : 'text-danger' %>"
                 style="font-size: smaller">
                <i class="fas fa-filter"></i>
            </div>
        </span>
    </h4>

    <% if ( groupDataOwner ) {  %>
        <% var group = app.model.SessionUser.getGroupById( groupDataOwner.team_id );%>
            <div class="card">
                <div class="card-header">
                    <i class="fas fa-info-circle"></i> <strong>Pro</strong>Tipp
                </div>
                <div class="card-body">
                    <p>
                        <%=raw _lc( 'HINT_GROUP_WITH_NO_APPOINTMENTS', [ group.getName() ] ) %>
                    </p>
                </div>
                <div class="card-footer">
                    <a href="#/appointment/create"
                       class="btn btn-sm btn-primary">
                        <%= _lc( 'BTN_CREATE_NEW_APPOINTMENT' ) %>
                    </a>
                </div>
            </div>
     <% }    %>

<% } else {   %>

    <% if ( true === currentUser.isOlderThanTwoWeeks() && false === currentUser.hasValidAddressData() )   {   %>

    <div class="row">
        <div class="col-sm-12">
            <div class="alert alert-info">
                <i class="fa fa-info-circle"></i>&nbsp;Bitte vervollständigen Sie Ihre Adressdaten. <a class="btn btn-sm btn-info" href="#/configuration/account/edit-address">Adressdaten hinterlegen</a>
            </div>
        </div>
    </div>

    <% }    %>

    <% var monthHeader = null, weekHeader = null, currentMonth, currentWeek, currentWeekMoment, a, mStart, mEnd, mDeadline; %>

    <% for ( var ai = 0; ai < appointments.length; ai++ ) { %>

        <% a = appointments[ ai ];  %>

        <% mStart = a.getMomentStart(); %>
        <% mEnd = a.getMomentEnd(); %>
        <% mDeadline = a.getMomentDeadline(); %>

        <% currentMonth = mStart.format( 'MMMM YYYY' ); %>
        <% currentWeekMoment = mStart.clone(); %>
        <% currentWeek = currentWeekMoment.startOf( 'week' ).format( 'D.M.' ) + " - " + currentWeekMoment.endOf( 'week' ).format( 'D.M.' ); %>

        <% if ( monthHeader != currentMonth ) {    %>

            <h4>
                <%= currentMonth %>
                <% if ( monthHeader === null ) {    %>
                    <span class="float-right clickable" style="margin-right: 12px">
                        <div data-type="btn-filter"
                             class="<%= ( false === filter.isModified ) ? 'text-primary' : 'text-danger' %>"
                             style="font-size: smaller">
                            <i class="fas fa-filter"></i>
                        </div>
                    </span>
                <% }    %>
            </h4>

            <% monthHeader = currentMonth; %>

        <% }    %>

        <% if ( weekHeader != currentWeek ) {    %>

            <h6 class="calendar-week">
                <%= currentWeek %>
            </h6>

            <% weekHeader = currentWeek; %>

        <% }    %>


        <div data-type="appointment-item-container"
             data-appointment-id="<%= a.getId() %>">
            <%=raw app.core.View.getTemplate( 'home-appointment-item', { a : a } ) %>
        </div>
    <% }    %>

    <%=raw app.core.View.getTemplate( 'home-pager', { pager : pager } )    %>

<% }    %>