{% load edc_subject_dashboard_extras %}
<!-- start appointments -->

<div id="apointments_list" class="table-responsive">
    <table class="table table-striped table-hover">
        <tbody>
        {% for wrapped in appointments %}
            {% if wrapped.visit_schedule_name == schedule_obj.visit_schedule.name and wrapped.schedule_name == schedule_obj.schedule.name %}
                <tr>
                    <td>
                      {% appointment_status_icon appt_status=wrapped.appt_status %} {{ wrapped.visit_code }}
                      {% if wrapped.visit_code_sequence %}.{{ wrapped.visit_code_sequence }}{% endif %}
                    </td>
                    <td>
                        <!--begin appointment button -->
                        {%  show_dashboard_appointment_button wrapped_appointment=wrapped view_appointment=perms.edc_appointment.view_appointment request=request %}
                        <!--end appointment button -->

                        {% if wrapped.appt_status == IN_PROGRESS_APPT%}
                            {% with wrapped.wrapped_visit as visit %}
                                {% if visit.id %}
                                    <a id="visit_report_btn_{{ wrapped.visit_code }}_{{ wrapped.visit_code_sequence }}" role="button" class="btn btn-sm btn-{% if wrapped.wrapped_visit.object.document_status == INCOMPLETE%}warning{% else %}default{% endif %}"
                                       {% if wrapped.object.site.id != request.site.id %} disabled {% endif %}
                                       href="{% if wrapped.object.site.id != request.site.id %}#{% else %}{{ visit.href }}{% endif %}" data-toggle="tooltip" title="Add/edit visit report">
                                        <i class="fas fa-pencil-alt fa-sm" aria-hidden="true"></i> Visit Report
                                    </a>
                                {% endif %}
                            {% endwith %}
                            {% forms_button wrapper=wrapped %}
                        {% elif wrapped.appt_status == COMPLETE_APPT %}
                            {% show_dashboard_visit_button wrapped_appointment=wrapped request=request %}
                        {% else %}
                          {% show_dashboard_visit_button wrapped_appointment=wrapped request=request %}
                        {% endif %}
                    </td>
                    <td>{% show_crf_totals wrapped_appointment=wrapped request=request %}</td>
                    <td>
                        <!--begin show missed label or nothing -->
                        {{ wrapped.object.title }}&nbsp{% if wrapped.object.visit.reason == MISSED_VISIT %}<span class="label label-default">MISSED</span>{% endif %}
                        <!--end show missed label or nothing -->
                    </td>

                    <td>
                        <!--begin unscheduled appointment button -->
                        {%  show_dashboard_unscheduled_appointment_button wrapped_appointment=wrapped view_appointment=perms.edc_appointment.view_appointment request=request %}
                        <!--end unscheduled appointment button -->
                    </td>
                        <!--begin show appt or visit report datetime -->
                        {% if wrapped.object.visit.report_datetime %}
                            <td>{{ wrapped.object.visit.report_datetime|date:"SHORT_DATE_FORMAT" }} {{ wrapped.object.visit.report_datetime|date:"D"| capfirst }}</td>
                        {% else %}
                            <td class="text text-muted">{{ wrapped.object.appt_datetime|date:"SHORT_DATE_FORMAT" }} {{ wrapped.object.appt_datetime|date:"D"| capfirst }}</td>
                        {% endif %}
                        <!--end show appt or visit report datetime -->
                </tr>
            {% endif %}
        {% endfor %}

        </tbody>
    </table>
</div>
<!-- end appointments -->
