{% extends "oneevent/base.html" %}
{% load tz %}

{% block heading_action %}OneEvent!{% endblock %}
{% block heading_title %}All your events{% endblock %}

{% block navbar_header_text %}Events List{% endblock %}

{% block navbar_extra %}
<ul class="nav navbar-nav">
    <li class="dropdown">
        <a href="#" class="dropdown-toggle"
            data-toggle="dropdown" title="Events">
            <span class="glyphicon glyphicon-list"></span>
            <span class="">
                {% if events_shown == 'fut' %}
                    Coming Up
                {% elif events_shown == 'past' %}
                    Past Events
                {% elif events_shown == 'all' %}
                    All Events
                {% elif events_shown == 'mine' %}
                    My Events
                {% elif events_shown == 'arch' %}
                    Archived Events
                {% endif %}
            </span>
            <span class="caret"></span>
        </a>
        <ul class="dropdown-menu" role="menu">
            <li><a href="{% url 'events_list_mine' %}">My events</a></li>
            <li><a href="{% url 'events_list_all' %}">All events</a></li>
            <li><a href="{% url 'events_list_future' %}">Coming up</a></li>
            <li><a href="{% url 'events_list_past' %}">Past events</a></li>
            <li class="divider"></li>
            <li><a href="{% url 'events_list_archived' %}">Archived events</a></li>
            <li class="divider"></li>
            <li><a href="{% url 'event_create' %}">
                 <span class="glyphicon glyphicon-plus"></span>
                 New event
             </a></li>
        </ul>
    </li>
</ul>
{% endblock %}

{% block content %}

<div class="row"><div class="table-responsive">
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>Event</th>
                <th>Date (local)</th>
                <th>Infos</th>
                <th>Organised by</th>
                {% if user.is_authenticated %}
                <th><!--  Actions --></th>
                {%endif%}
            </tr>
        </thead>
        <tbody>
            {% for event_info in events %}
            {% timezone event_info.event.get_tzinfo %}
            <tr>
                <td>
                    <p>
                        {{ event_info.event.title }}
                        <span class="badge pull-right">{{ event_info.event.city }}</span>
                    </p>
                    {% if event_info.event.location_name %}<p><small>at </small>{{event_info.event.location_name}}</p>{% endif %}
                </td>
                <td><p>{{ event_info.event.start|date:"D, d N Y H:i" }}</p>
                    {% if event_info.event.end %}<p>- {{ event_info.event.end|date:"D, d N Y H:i" }}</p>{% endif %}
                    <p></p>
                </td>
                <td>
                    {% if event_info.event.max_participant > 0 %}
                    <p>Participants: {{event_info.event.get_active_bookings.count}}/{{event_info.event.max_participant}}</p>
                    {% endif %}
                    {% if event_info.event.booking_close %}
                    <p>Registration closes: {{event_info.event.booking_close|date:"D, d N Y H:i"}}</p>
                    {% endif %}
                    {% if event_info.event.choices_close %}
                    <p>Choices closes: {{event_info.event.choices_close|date:"D, d N Y H:i"}}</p>
                    {% endif %}
                    {% if event_info.price_for_user %}
                    <p>Price for you:
                        {% if event_info.price_for_user > 0 %}
                            {{ event_info.price_for_user }}{% if event_info.event.price_currency %}({{event_info.event.price_currency}}){% endif %}
                        {% else %}
                            Free
                        {% endif %}
                    </p>
                    {% endif %}
                </td>
                <td>{% for orga in event_info.event.organisers.all %}<p>{{orga.get_full_name}}</p>{% endfor %}</td>
                {% if user.is_authenticated %}
                <td>
                <div>
                {% if event_info.booking %}
                    {% if event_info.event.is_choices_open %}
                    <a href="{% url 'booking_update' booking_id=event_info.booking.id %}" class="btn btn-success">
                        {% if event_info.event.choices.count > 0  %}
                        Choices
                        {% else %}
                        Update
                        {% endif %}
                    </a>
                    {% else %}
                    <button type="button" class="btn btn-success disabled enable-tooltip"
                        data-toggle="tooltip" data-placement="top" title="Too late Vicky! ;-)">Choices Closed</button>
                    {% endif %}
                    {% if event_info.user_can_cancel %}
                    <a href="{% url 'booking_cancel' booking_id=event_info.booking.id %}" class="btn btn-danger">Unregister</a>
                    {% else %}
                    <button type="button" class="btn btn-danger disabled enable-tooltip"
                        data-toggle="tooltip" data-placement="top" title="Too late Vicky! ;-)">Event Closed</button>
                    {% endif %}
                {% elif event_info.user_can_book %}
                    {% if event_info.event.is_booking_open %}
                        {% if event_info.event.is_fully_booked %}
                        <button type="button" class="btn btn-info disabled enable-tooltip"
                            data-toggle="tooltip" data-placement="top" title="Too late Vicky! ;-)">Event Full</button>
                        {% else %}
                        <a href="{% url 'booking_create' event_id=event_info.event.id %}" class="btn btn-info">Register</a>
                        {% endif %}
                    {% else %}
                        <button type="button" class="btn btn-info disabled enable-tooltip"
                            data-toggle="tooltip" data-placement="top" title="Too late Vicky! ;-)">Event Closed</button>
                    {% endif %}
                {% endif %}
                </div>

                {% if event_info.user_can_update %}
                <div>
                    <a href="{% url 'event_manage' event_id=event_info.event.id %}"
                       class="btn btn-sm btn-primary">Manage</a>
                    <a href="{% url 'event_update' event_id=event_info.event.id %}"
                       class="btn btn-sm btn-warning">Edit</a>
                    ({{event_info.event.get_pub_status_display }})
                </div>
                {% endif %}
                </td>
                {% endif %}
            </tr>
            {% endtimezone %}
            {% endfor %}
        </tbody>
    </table>
</div></div>

{% endblock %}
