{% extends 'base_rigs.html' %}
{% load paginator from filters %}
{% load button from filters %}

{% block content %}
<div class="table-responsive">
    <table class="table mb-0 table-sm">
        <thead>
            <tr>
                <th scope="col">Event</th>
                <th scope="col">MIC</th>
                <th scope="col">Dates</th>
                <th scope="col">RA</th>
                <th scope="col">Checklists</th>
                <th scope="col">Power Records</th>
            </tr>
        </thead>
        <tbody>
        {% for event in object_list %}
        <tr id="event_row">
            <th scope="row" id="event_number"><a href="{% url 'event_detail' event.pk %}">{{ event }}</a><br><small>{{ event.get_status_display }}</small></th>
            <td>{% if event.mic is not None %}<a href="{% url 'profile_detail' event.mic.pk %}">{% else %}<span class="text-danger">{% endif %}{{ event.mic }}{% if event.mic is not None %}</a>{% else %}</span>{%endif%}</td>
            <!--Dates-->
            <td id="event_dates">
                <span><strong>{{ event.start_date|date:"D d/m/Y" }}</strong></span>
                {% if event.end_date and event.end_date != event.start_date %}
                    <br><span><strong>{{ event.end_date|date:"D d/m/Y"  }}</strong></span>
                {% endif %}
            </td>
            <td>{% include 'partials/hs_status.html' with event=event object=event.riskassessment view='ra_detail' edit='ra_edit' create='event_ra' review='ra_review' perm=perms.RIGS.review_riskassessment %}</td>
            <td>
            {% for checklist in event.checklists.all %}
            {% include 'partials/hs_status.html' with event=event object=checklist view='ec_detail' edit='ec_edit' create='event_ec' review='ec_review' perm=perms.RIGS.review_eventchecklist %}
            <br>
            {% endfor %}
            <a href="{% url 'event_ec' event.pk %}" class="btn btn-info"><span class="fas fa-paperclip"></span> <span
            class="d-none d-sm-inline">Create</span></a>
            </td>
            <td>
            {% for record in event.power_tests.all %}
            {% include 'partials/hs_status.html' with event=event object=record view='pt_detail' edit='pt_edit' create='event_pt' review='pt_review' perm=perms.RIGS.review_power %}
            <br/>
            {% endfor %}
            <a href="{% url 'event_pt' event.pk %}" class="btn btn-info"><span class="fas fa-paperclip"></span> <span
            class="hidden-xs">Create</span></a>
            </td>
        </tr>
        {% empty %}
        <tr class="bg-warning text-dark">
            <td colspan="6">No events found</td>
        </tr>
        {% endfor %}
        </tbody>
    </table>
    {% if is_paginated %}
    <div class="row justify-content-center">
        {% paginator %}
    </div>
    {% endif %}
</div>
{% endblock %}
