{% load custom_tags_and_filters %}
<table class="table table-condensed table-double-stripped thead-light" style="border: 1px solid #ddd">
    <thead>
        <tr>
            <th>Created</th>
            <th class="text-center">Access</th>
            <th class="text-center">Requested start</th>
            <th class="text-center">Requested end</th>
            <th class="text-center">Users</th>
            <th class="text-center">
                {% if request_status == 'pending' and user_is_reviewer %}
                    Action
                {% elif request_status == 'approved' %}
                    Approved by
                {% elif request_status == 'denied' %}
                    Denied by
                {% endif %}
            </th>
        </tr>
    </thead>
    <tbody>
        {% for a_request in access_request_list %}
            <tr>
                <td style="vertical-align: middle">
                    {% if a_request.id in access_request_notifications %}<span class="label label-success">New</span>{% endif %}
                    {{ a_request.creation_time|date:'SHORT_DATETIME_FORMAT' }}
                </td>
                <td class="text-center" style="vertical-align: middle">
                    {{ a_request.physical_access_level.display_value_for_select }}
                </td>
                <td class="text-center" style="vertical-align: middle">{{ a_request.start_time|date:'SHORT_DATETIME_FORMAT' }}</td>
                <td class="text-center" style="vertical-align: middle">{{ a_request.end_time|date:'SHORT_DATETIME_FORMAT' }}</td>
                <td style="vertical-align: middle">
                    <ul style="padding-inline-start: 25px; margin-bottom: 0">
                        <li>
                            <b>{{ a_request.creator }}</b>
                        </li>
                        {% for other_user in a_request.other_users.all %}<li>{{ other_user }}</li>{% endfor %}
                    </ul>
                </td>
                <td class="text-center text-nowrap" style="vertical-align: middle">
                    {% if request_status == 'pending' and user in a_request.reviewers %}
                        <a class="btn btn-sm btn-default"
                           title="Approve/Deny"
                           href="{% url 'edit_access_request' a_request.id %}"><i class="glyphicon glyphicon-ok-circle success-highlight"></i>&nbsp;&nbsp;<i class="glyphicon glyphicon-ban-circle danger-highlight"></i> Review</a>
                    {% elif request_status == 'pending' and a_request.creator == user %}
                        {% url 'edit_access_request' a_request.id as edit_request_url %}
                        {% url 'delete_access_request' a_request.id as delete_request_url %}
                        {% button type="edit" size="small" value="Edit" title="Edit request" url=edit_request_url %}
                        {% button type="delete" size="small" value="Delete" title="Delete request" url=delete_request_url onclick="return confirm('Are you sure you want to delete this request?');" %}
                    {% elif request_status == 'approved' or request_status == 'denied' %}
                        {{ a_request.reviewer.get_name }}
                    {% endif %}
                </td>
            </tr>
            <tr>
                {% if a_request.description %}
                    <td colspan="6" style="border: none">
                        {% if a_request.description %}
                            <u>Description:</u>
                            <br>
                            {{ a_request.description|linebreaksbr }}
                        {% endif %}
                    </td>
                {% endif %}
            </tr>
        {% endfor %}
    </tbody>
</table>
