{% extends "eventum_admin.html" %}
{% import "eventum_macros.html" as macros %}

{% set active_page='Events' %}

{% block title %}View Events{% endblock %}
{% block pagetitle %}Events{% endblock %}
{% block pagelink %}{{ url_for('events.index') }}{% endblock %}
{% block bodyClass %}{{ super() }} events{% endblock %}

{% if request.args.get('past') %}
{% set past = request.args.get('past')|int %}
{% else %}
{% set past = 0 %}
{% endif %}
{% if request.args.get('future') %}
{% set future = request.args.get('future')|int %}
{% else %}
{% set future = 0 %}
{% endif %}

{% block js %}
{{ super() }}
<script type="text/javascript" src="{{ url_for('eventum.static', filename='js/events/events.js') }}"></script>
{% endblock %}

{% macro render_event(event) %}
<li
    {% if not event.ready_for_publishing() %}
    class="incomplete event"
    {% elif event.published %}
    class="published event"
    {% else %}
    class="unpublished event"
    {% endif %}
    >
    <div class="event-image">
        <a href="{{ url_for('events.edit', event_id=event.id) }}">
            <i style="background-image:url({{ event.image_url() }});"></i>
            <h3>{{event.title}}</h3>
        </a>
    </div>
    <div class="text-content">
        <ul class="links">
            {% if event.facebook_url %}
            <li>
                <a href="{{ event.facebook_url }}">
                    <span><i class="fa fa-facebook"></i></span>
                </a>
            </li>
            {% endif %}
            {% if event.published %}
            <li>
                <a href="{{ event.get_absolute_url() }}">
                    <span><i class="fa fa-external-link"></i></span>
                </a>
            </li>
            {% endif %}
        </ul>
        {% if event.location %}
            <p>
                <a href="{{ url_for('events.edit', event_id=event.id) }}">
                    <i class="fa fa-map-marker"></i>
                    {{ event.location }}
                </a>
            </p>
        {% else %}
            <p class="missing">
                <a href="{{ url_for('events.edit', event_id=event.id) }}">
                    <i class="fa fa-map-marker"></i>
                    No Location Set
                </a>
            </p>
        {% endif %}
        {% if event.is_multiday() %}
        <p>
            <a href="{{ url_for('events.edit', event_id=event.id) }}">
                <i class="fa fa-calendar"></i>
                {{ event.human_readable_datetime() }}
            </a>
        </p>
        {% else %}
        <p>
            <a href="{{ url_for('events.edit', event_id=event.id) }}">
                <i class="fa fa-calendar"></i>
                {{ event.human_readable_date() }}
            </a>
        </p>
        <p>
            <a href="{{ url_for('events.edit', event_id=event.id) }}">
                <i class="fa fa-clock-o"></i>
                {{ event.human_readable_time() }}
            </a>
        </p>
        {% endif %}
    </div>
    <div class="creator">
        <a href="{{ url_for('users.user', slug=event.creator.slug) }}">
            <span class="profile-image">
                <img src="{{ event.creator.get_profile_picture() }}">
            </span>
            <p class="name">{{ event.creator.name }}</p>
        </a>
    </div>
</li>
{% endmacro %}

{% macro render_week (week_name, events) %}
{% if week_name %}
<h2>{{ week_name }}</h2>
{% endif %}
<div class="events-wrapper">
    <ul class="events clearfix"
        style="width:{{ 16.5*(events|count) - 1 }}rem;">
    {% if events %}
        {% for event in events %}
        {{ render_event(event) }}
        {% endfor %}
    {% else %}
        <li class="no-events">
            <p>No events this week</p>
        </li>
    {% endif %}
    </ul>
</div>
{% endmacro%}

{% block barright %}
<a href="{{ url_for('events.create') }}">
    <i class="fa fa-plus fa-2x"></i>
</a>
{% endblock %}

{% block content %}
<div class="pagination">
    <div class="past">
        <a href="{{url_for('events.index', future=future, past=(past + 1)) }}">
            <p>Past events</p>
        </a>
    </div>
</div>
{% for week in past_events %}
<div class="past-week week">
    {{ render_week("Week of " + week.week_name, week.events) }}
</div>
{% endfor %}
<div class="this-week week">
    {{ render_week("This Week", this_week) }}
</div>
<div class="next-week week">
    {{ render_week("Next Week", next_week) }}
</div>
{% for week in future_events %}
<div class="future-week week">
    {{ render_week("Week of " + week.week_name, week.events) }}
</div>
{% endfor %}
<div class="pagination" id="bottom">
    <div class="future">
        <a href="{{url_for('events.index', future=(future + 1), past=past) }}#bottom">
            <p>Future events</p>
        </a>
    </div>
</div>
{% endblock %}
