{% load i18n %}
{% load event_tags %}
<div class="event-wrap">
    <div class="time-stamp">
        {{ event.start_dt|date:"D, M j, Y" }}
        
        {% if event.start_dt < now %}
            {% if event.end_dt < now %}
                <div class="age-msg" title="about {{ event.start_dt|timesince }} ago">
                    {% trans "Past event" %}
                </div>
            {% else %}
                <div class="age-msg" title="about {{ event.start_dt|timesince }} ago">
                    {% trans "Ongoing event" %}
                </div>
            {% endif %}
        {% else %}
        <div class="age-msg" title ="in about {{ event.start_dt|timeuntil }}">
            {{ event.start_dt|timeuntil }}
        </div>
        {% endif %}
        
        {% if event.type %}
            <style type="text/css">
                .event-type-label {
                    margin: 5px;
                    padding: 3px 5px;
                    font-size: 11px;
                }
            </style>
            <div class="event-type-label"
            style="color:#{{ event.type.color_set.fg_color }}; 
            background-color:#{{ event.type.color_set.bg_color }}"
            title="{{ event.type.name }}">
            {{ event.type.name|truncatewords:3 }}
            </div>
        {% endif %}

    </div>
    <div class="event-info">
        <h3>
        {% if event.priority %}
            <div class="event-priority"></div>
        {% endif %}
        <a href="{% url event event.pk %}">{{ event.title }}</a>
        </h3>
        <div class="place">{{ event.place }}</div>

        <div class="time-period">
            {{ event.start_dt|date:"l, M j, Y P" }} - {{ event.end_dt|date:"l, M j, Y P" }}
        </div> 

        <div class="description">
            {{ event.description|striptags|safe|truncatewords:40 }}
        </div>

        {% if event.registration_configuration.enabled %}

            {% if now > event.end_dt or now > event.registration_configuration.end_dt %}

            <div class="attend-wrap closed">
                {% include "events/include/search-result-spots-taken.html" %}
                <div class="attend"><a href="">{% trans "Registration Closed" %}</a></div>
                <div style="clear:both;"></div>
            </div>
            
            {% else %}

            {% is_registered_user user event as registered_user %}
            {% if registered_user %}
            <div class="attend-wrap registered">
                {% include "events/include/search-result-spots-taken.html" %}
                <div class="attend"><a href="{% url event.myevents %}">{% trans "You are registered" %}</a></div>
                <div style="clear:both;"></div>
            </div>
            {% else %}
            <div class="attend-wrap">
                {% include "events/include/search-result-spots-taken.html" %}
                <div class="attend"><a href="{% url event event.pk %}">{% trans "Attend this event" %}</a></div>
                <div style="clear:both;"></div>
            </div>
            {% endif %}

            {% endif %}

        {% endif %}

    </div>
    <div style="clear:both;"></div>
    {% include 'events/meta.html' %}
    <!-- delete-event form -->
    <form name="event-delete" method="POST" action="{% url event.delete event.pk %}">{% csrf_token %}
        <input type="hidden" name="action" value="delete">
    </form>
</div>
