{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}

{% load markdown_tags %}
{% load button from filters %}
{% load static %}

{% block content %}
<div class="row my-3 py-3">
    {% if not request.is_ajax %}
        {% if perms.RIGS.view_event %}
        <div class="col-sm-12 text-right">
            {% include 'partials/event_detail_buttons.html' %}
        </div>
        {% endif %}
    {% endif %}
    {% if object.is_rig and perms.RIGS.view_event %}
        {# only need contact details for a rig #}
        <div class="col-md-6">
            {% include 'partials/contact_details.html' %}
        </div>
    {% endif %}
    <div class="col-md-6">
        {% include 'partials/event_details.html' %}
    </div>
    {% if not event.dry_hire %}
    <div class="col {% if event.is_rig %}py-3{%endif %}">
        {% include 'partials/hs_details.html' %}
    </div>
    {% endif %}
    {% if event.is_rig %}
        {% if event.is_rig and event.internal and perms.RIGS.view_event %}
        <div class="col-md-8 py-3">
            {% include 'partials/auth_details.html' %}
        </div>
    {% endif %}
    {% endif %}
    {% if not request.is_ajax and perms.RIGS.view_event %}
    <div class="col-sm-12 text-right">
        {% include 'partials/event_detail_buttons.html' %}
    </div>
    {% endif %}
    {% if event.is_rig %}
        <div class="col-sm-12">
            <div class="card card-default">
                <div class="card-header">Event Details</div>
                <div class="card-body">
                    {% if perms.RIGS.view_event %}
                    <h4>Notes</h4>
                    <hr>
                    <p class="dont-break-out">{{ event.notes|markdown }}</p>
                    {% endif %}
                    <br>
                    {% include 'partials/item_table.html' %}
                </div>
            </div>
        </div>
        {% if event.can_check_in %}
        <div class="col-sm-12">
            <div class="card mt-3">
                <div class="card-header">Crew Record</div>
                <div class="table-responsive">
                    <table class="table table-sm">
                        <thead>
                            <tr>
                                <th scope="col">Name</th>
                                <th scope="col">Vehicle</th>
                                <th scope="col">Start Time</th>
                                <th scope="col">Role</th>
                                <th scope="col">End Time</th>
                                <th scope="col">{% if request.user.pk is event.mic.pk %}<a href="{% url 'event_checkin_override' event.pk %}" class="btn btn-sm btn-success"><span class="fas fa-plus"></span> Add</a>{% endif %}</th>
                            </tr>
                        </thead>
                        <tbody id="crewmembers">
                            {% for crew in object.crew.all %}
                            <tr>
                                <td>{{crew.person}}</td>
                                <td>{{crew.vehicle|default:"None"}}</td>
                                <td>{{crew.time}}</td>
                                <td>{{crew.role}}</td>
                                <td>{% if crew.end_time %}{{crew.end_time}}{% else %}<span class="text-success fas fa-clock" data-toggle="tooltip" title="This person is currently checked into this event"></span>{% endif %}</td>
                                <td>{% if crew.end_time %}{% if crew.person.pk == request.user.pk or event.mic.pk == request.user.pk %}{% button 'edit' 'edit_checkin' crew.pk clazz='btn-sm modal-href' %}{% endif %}{%endif%}</td>
                            </tr>
                            {% empty %}
                            <tr>
                                <td colspan="6" class="text-center bg-warning">Apparently this event happened by magic...</td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                    </div>
            </div>
            {% endif %}
        </div>
        {% if not request.is_ajax and perms.RIGS.view_event %}
        <div class="col-sm-12 text-right">
            {% include 'partials/event_detail_buttons.html' %}
        </div>
        {% endif %}
    {% endif %}
    {% if not request.is_ajax and perms.RIGS.view_event %}
        <div class="col-sm-12 text-right">
            {% include 'partials/last_edited.html' with target="event_history" %}
        </div>
    {% endif %}
</div>
{% endblock %}

{% if request.is_ajax %}
    {% block footer %}
            {% if perms.RIGS.view_event %}
                {% include 'partials/last_edited.html' with target="event_history" %}
            {% endif %}
            <a href="{% url 'event_detail' object.pk %}" class="btn btn-primary">Open Event Page <span class="fas fa-eye"></span></a>
    {% endblock %}
{% endif %}
