{% extends request.is_ajax|yesno:"base_ajax.html,base_rigs.html" %}
{% load linkornone from filters %}
{% load namewithnotes from filters %}

{% block title %}{% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %} | {{object.name}}{% endblock %}

{% block content %}
<div class="row my-3 py-3">
    {% if not request.is_ajax %}
        <div class="col-sm-12">
                <h1>
                    {% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %}
                    | {{ object.name }} {% if event.dry_hire %}<span class="badge badge-secondary">Dry Hire</span>{% endif %}
                </h1>
        </div>
        {% if perms.RIGS.view_event %}
        <div class="col-sm-12 text-right">
            {% include '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">
            {% if event.person %}
            <div class="card card-default mb-3">
                <div class="card-header">Contact Details</div>
                <div class="card-body">
                    <dl class="row">
                        <dt class="col-sm-6">Person</dt>
                        <dd class="col-sm-6">
                            {% if object.person %}
                                <a href="{% url 'person_detail' object.person.pk %}" class="modal-href">
                                    {{ object.person|namewithnotes:'person_detail' }}
                                </a>
                            {% endif %}
                        </dd>
                        <dt class="col-sm-6">Email</dt>
                        <dd class="col-sm-6">{{ object.person.email|linkornone:'mailto' }}</dd>
                        <dt class="col-sm-6">Phone Number</dt>
                        <dd class="col-sm-6">{{ object.person.phone|linkornone:'tel' }}</a></dd>
                    </dl>
                </div>
            </div>
            {% endif %}
            {% if event.organisation %}
                <div class="card card-default">
                    <div class="card-header">Organisation</div>
                    <div class="card-body">
                        <dl class="row">
                            <dt class="col-sm-6">Organisation</dt>
                            <dd class="col-sm-6">
                                {% if object.organisation %}
                                    <a href="{% url 'organisation_detail' object.organisation.pk %}" class="modal-href">
                                        {{ object.organisation|namewithnotes:'organisation_detail' }}
                                    </a>
                                {% endif %}
                            </dd>
                            <dt class="col-sm-6">Email</dt>
                            <dd class="col-sm-6">{{ object.organisation.email|linkornone:'mailto' }}</dd>
                            <dt class="col-sm-6">Phone Number</dt>
                            <dd class="col-sm-6">{{ object.organisation.phone|linkornone:'tel' }}</a></dd>
                            <dt class="col-sm-6">Has SU Account</dt>
                            <dd class="col-sm-6">{{ event.organisation.union_account|yesno|capfirst }}</dd>
                        </dl>
                    </div>
                </div>
            {% endif %}
        </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 '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|linebreaksbr }}</p>
                    {% endif %}
                    <br>
                    {% include 'item_table.html' %}
                </div>
            </div>
        </div>
        {% if not request.is_ajax and perms.RIGS.view_event %}
        <div class="col-sm-12 text-right">
            {% include '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 %}
