{% extends request.is_ajax|yesno:"base_ajax.html,base.html" %}
{% block title %}Event {% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}
{% endif %}{% endblock %}

{% block content %}
<div class="row">
    {% if not request.is_ajax %}
    <div class="col-sm-12">
        <div class="col-sm-8">
            <h1>Event {% if object.is_rig %}N{{ object.pk|stringformat:"05d" }}{% else %}{{ object.pk }}{% endif %}</h1>
        </div>
    </div>
        <div class="col-sm-12 text-right">
            <div class="btn-group btn-page">
                <a href="{% url 'event_update' event.pk %}" class="btn btn-default"><span
                        class="glyphicon glyphicon-edit"></span> <span
                            class="hidden-xs">Edit</span></a>
                {% if event.is_rig %}
                    <a href="{% url 'event_print' event.pk %}" target="_blank" class="btn btn-default"><span
                            class="glyphicon glyphicon-print"></span> <span
                            class="hidden-xs">Print</span></a>
                {% endif %}
                <a href="{% url 'event_duplicate' event.pk %}" class="btn btn-default" title="Duplicate Rig"><span
                        class="glyphicon glyphicon-duplicate"></span> <span
                            class="hidden-xs">Duplicate</span></a>
                {% if event.is_rig %}
                    {% if perms.RIGS.add_invoice %}
                        <a href="{% url 'invoice_event' event.pk %}" class="btn btn-default" title="Invoice Rig"><span
                                class="glyphicon glyphicon-gbp"></span> <span
                            class="hidden-xs">Invoice</span></a>
                    {% endif %}
                {% endif %}
            </div>
        </div>
    
    {% endif %}
    {% if object.is_rig %}
        {# only need contact details for a rig #}
        <div class="col-sm-12 col-md-6 col-lg-5">
            <div class="panel panel-default">
                <div class="panel-heading">Contact Details</div>
                <div class="panel-body">
                    <dl class="dl-horizontal">
                        <dt>Person</dt>
                        <dd>
                            {% if object.person %}
                                <a href="{% url 'person_detail' object.person.pk %}" class="modal-href">
                                    {{ object.person }}
                                </a>
                            {% endif %}
                        </dd>

                        <dt>Email</dt>
                        <dd>
                            <a href="mailto:{{object.person.email}}" target="_blank">
                                {{ object.person.email }}
                            </a>
                        </dd>

                        <dt>Phone Number</dt>
                        <dd><a href="tel:{{object.person.phone}}">{{ object.person.phone }}</a></dd>
                    </dl>
                </div>
            </div>
            {% if event.organisation %}
                <div class="panel panel-default">
                    <div class="panel-heading">Organisation</div>
                    <div class="panel-body">
                        <dl class="dl-horizontal">
                            <dt>Organisation</dt>
                            <dd>
                                {% if object.organisation %}
                                    <a href="{% url 'organisation_detail' object.organisation.pk %}" class="modal-href">
                                        {{ object.organisation }}
                                    </a>
                                {% endif %}
                            </dd>

                            <dt>Phone Number</dt>
                            <dd>
                                <a href="tel:{{object.person.phone}}">
                                    {{ object.organisation.phone }}
                                </a>
                            </dd>

                            <dt>Has SU Account</dt>
                            <dd>{{ event.organisation.union_account|yesno|capfirst }}</dd>
                        </dl>
                    </div>
                </div>
            {% endif %}
        </div>
    {% endif %}
    <div class="col-sm-12 {% if event.is_rig %}col-md-6 col-lg-7{% endif %}">
        <div class="panel panel-info">
            <div class="panel-heading">{{ object.name }}</div>
            <div class="panel-body">
                <dl class="dl-horizontal">
                    <dt>Event Venue</dt>
                    <dd>
                        {% if object.venue %}
                            <a href="{% url 'venue_detail' object.venue.pk %}" class="modal-href">
                                {{ object.venue }}
                            </a>
                        {% endif %}
                    </dd>

                    {% if event.is_rig %}
                        <dt>Event MIC</dt>
                        <dd>{{ event.mic.name }}</dd>
                    {% endif %}

                    <dt>Status</dt>
                    <dd>{{ event.get_status_display }}</dd>

                    <dd>&nbsp;</dd>

                    {% if event.is_rig %}
                        <dt>Crew Meet</dt>
                        <dd>{{ event.meet_at|date:"d M Y H:i"|default:"" }}</dd>
                        <dd>{{ event.meet_info|default:"" }}</dd>

                        <dt>Access From</dt>
                        <dd>{{ event.access_at|date:"d M Y H:i"|default:"" }}</dd>
                    {% endif %}

                    <dt>Event Starts</dt>
                    <dd>{{ event.start_date|date:"d M Y" }} {{ event.start_time|date:"H:i" }}</dd>

                    <dt>Event Ends</dt>
                    <dd>{{ event.end_date|date:"d M Y" }} {{ event.end_time|date:"H:i" }}</dd>

                    <dd>&nbsp;</dd>

                    <dt>Event Description</dt>
                    <dd>{{ event.description|linebreaksbr }}</dd>

                    <dd>&nbsp;</dd>

                    <dt>Based On</dt>
                    <dd>
                        {% if object.based_on %}
                            <a href="{% url 'event_detail' pk=object.based_on.pk %}">
                                {% if object.based_on.is_rig %}N{{ object.based_on.pk|stringformat:"05d" }}{% else %}
                                    {{ object.based_on.pk }}{% endif %}
                                {{ object.base_on.name }} by {{ object.based_on.mic.name }}
                            </a>
                        {% endif %}
                    </dd>

                    {% if event.dry_hire %}
                        <dt>Checked In By</dt>
                        <dd>{{ object.checked_in_by.name }}</dd>
                    {% endif %}

                    {% if event.is_rig %}
                        <dt>Collected By</dt>
                        <dd>{{ object.collector }}</dd>
                    {% endif %}
                </dl>
            </div>
        </div>
    </div>
    {% if not request.is_ajax %}
    <div class="col-sm-12 text-right">
        <div class="btn-group btn-page">
            <a href="{% url 'event_update' event.pk %}" class="btn btn-default"><span
                    class="glyphicon glyphicon-edit"></span> <span
                        class="hidden-xs">Edit</span></a>
            {% if event.is_rig %}
                <a href="{% url 'event_print' event.pk %}" target="_blank" class="btn btn-default"><span
                        class="glyphicon glyphicon-print"></span> <span
                        class="hidden-xs">Print</span></a>
            {% endif %}
            <a href="{% url 'event_duplicate' event.pk %}" class="btn btn-default" title="Duplicate Rig"><span
                    class="glyphicon glyphicon-duplicate"></span> <span
                        class="hidden-xs">Duplicate</span></a>
            {% if event.is_rig %}
                {% if perms.RIGS.add_invoice %}
                    <a href="{% url 'invoice_event' event.pk %}" class="btn btn-default" title="Invoice Rig"><span
                            class="glyphicon glyphicon-gbp"></span> <span
                        class="hidden-xs">Invoice</span></a>
                {% endif %}
            {% endif %}
        </div>
    </div>
    {% endif %}
    {% if event.is_rig %}
        <div class="col-sm-12">
            <div class="panel panel-default">
                <div class="panel-heading">Event Details</div>
                <div class="panel-body">
                    <div class="well well-sm">
                        <h4>Notes</h4>
                        {{ event.notes|linebreaksbr }}
                    </div>
                    {% include 'RIGS/item_table.html' %}
                </div>
            </div>
        </div>
        {% if not request.is_ajax %}
        <div class="col-sm-12 text-right">
            <div class="btn-group btn-page">
                <a href="{% url 'event_update' event.pk %}" class="btn btn-default"><span
                        class="glyphicon glyphicon-edit"></span> <span
                            class="hidden-xs">Edit</span></a>
                {% if event.is_rig %}
                    <a href="{% url 'event_print' event.pk %}" target="_blank" class="btn btn-default"><span
                            class="glyphicon glyphicon-print"></span> <span
                            class="hidden-xs">Print</span></a>
                {% endif %}
                <a href="{% url 'event_duplicate' event.pk %}" class="btn btn-default" title="Duplicate Rig"><span
                        class="glyphicon glyphicon-duplicate"></span> <span
                            class="hidden-xs">Duplicate</span></a>
                {% if event.is_rig %}
                    {% if perms.RIGS.add_invoice %}
                        <a href="{% url 'invoice_event' event.pk %}" class="btn btn-default" title="Invoice Rig"><span
                                class="glyphicon glyphicon-gbp"></span> <span
                            class="hidden-xs">Invoice</span></a>
                    {% endif %}
                {% endif %}
            </div>
            <div>Last edited at {{ object.last_edited_at|date:"SHORT_DATETIME_FORMAT" }}
                by {{ object.last_edited_by.name }}.
            </div>
        </div>
        {% endif %}
    {% endif %}
</div>
{% endblock %}

{% if request.is_ajax %}
    {% block footer %}
        <div class="row">
            <div class="col-sm-10 align-left">
                Lasted edited at {{ object.last_edited_at|date:"SHORT_DATE_FORMAT" }} by {{ object.last_edited_by.name }}
            </div>
            <div class="col-sm-2">
                <div class="pull-right">
                    <a href="{% url 'event_detail' object.pk %}" class="btn btn-primary">Open Event Page <span
                            class="glyphicon glyphicon-eye"></span></a>
                </div>
            </div>
        </div>
    {% endblock %}
{% endif %}
