{% load i18n leprikon_tags sekizai_tags thumbnail %}

<div class="box box-{{ object.subject_type.subject_type }} box-{{ object.subject_type.slug }}">
    <div class="box-header">
        <strong>{{ object.display_name }}</strong>
        {% for group in object.all_groups %}
        <small class="tag" style="color: {{ group.font_color }}; border-color: {{ group.font_color }}; background-color: {{ group.color }}">
            {{ group.name }}
        </small>
        {% endfor %}
        {% if object.price %}
        <small>{{ object.price | currency }}{% if object.school_year_division.period_name %} / {{ object.school_year_division.period_name }}{% endif %}</small>
        {% endif %}
        {% if request.user.is_staff or request.leader in object.all_leaders %}
        <a class="btn btn-primary btn-xs" href="{% url_with_back 'leprikon:subject_update' object.subject_type.slug object.id %}">
            <span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
            {% trans 'edit' %}
        </a>
        {% endif %}
    </div>

    <div class="box-content">
        {% if object.photo %}
        <a href="{% thumbnail object.photo 1500x1500 %}" data-toggle="lightbox" data-title="{{ object.photo.name }}">
            <img class="right" alt="{{ object.photo.name }}" src="{% thumbnail object.photo 200x200 %}" />
        </a>
        {% endif %}

        {% if object.start_date %}{# event #}
        <p>
            {% trans 'Start' %}: {{ object.start_date }}{% if objec.start_time %}, {{ objec.start_time }}{% endif %}
            {% if object.start_date != object.end_date or objec.end_time %}
                <br/>
                {% trans 'End' %}:
                {% if object.start_date != object.end_date %}
                    {{ object.end_date }}{% if objec.end_time %}, {{ objec.end_time }}{% endif %}
                {% else %}
                    {{ objec.end_time }}
                {% endif %}
            {% endif %}
            {% if object.place %}
                <br/>
                {% trans 'Place' %}: {{ object.place }}
            {% endif %}
        </p>
        {% elif object.all_times or object.place %}{# course #}
        <p>
            {% if object.all_times %}{% trans 'Time' %}: {{ object.all_times | comma_separated }}{% endif %}
            {% if object.all_times and object.place %}<br/>{% endif %}
            {% if object.place %}{% trans 'Place' %}: {{ object.place }}{% endif %}
        </p>
        {% endif %}

        {{ object.description | safe }}

        {% if object.all_age_groups %}
        <p>
            {% if object.all_age_groups|length > 1 %}{% trans 'Age groups' %}{% else %}{% trans 'Age group' %}{% endif %}:
            {{ object.all_age_groups|comma_separated }}
        </p>
        {% endif %}

        {% if object.all_target_groups %}
        <p>
            {% if object.all_target_groups|length > 1 %}{% trans 'Target groups' %}{% else %}{% trans 'Target group' %}{% endif %}:
            {{ object.all_target_groups|comma_separated }}
        </p>
        {% endif %}

        {% if object.all_leaders %}
        <p>
            {% blocktrans count counter=object.all_leaders|length %}Led by{% plural %}Led by{% endblocktrans %}
            {{ object.get_leaders_list }}
        </p>
        {% endif %}

        {% if object.subject_type.all_attachments or object.all_attachments %}
        <p>
            {% trans 'Attachments' %}:
            {% for attachment in object.subject_type.all_attachments %}
            <a href="{{ attachment.file.url }}">{{ attachment.file }}</a>
            {% endfor %}
            {% for attachment in object.all_attachments %}
            <a href="{{ attachment.file.url }}">{{ attachment.file }}</a>
            {% endfor %}
        </p>
        {% endif %}

        {% if object.page %}
        <p>
            {% trans 'More information' %}:
            <a href="{{ object.page.get_absolute_url }}">
                {{ object.page.get_title }}
            </a>
        </p>
        {% endif %}

        <p>{% registration_links object %}</p>

        {% if request.user.is_staff or request.leader in object.all_leaders %}
        <div class="btn-group">
            <a class="btn btn-sm btn-default" href="{% url_with_back 'leprikon:subject_registrations' object.subject_type.slug object.id %}">
                {% trans 'registrations' %}
                ({{ object.approved_registrations_count }}{% if object.unapproved_registrations_count %} + {{ object.unapproved_registrations_count }}{% endif %})
            </a>
            <a class="btn btn-sm btn-default" href="{% url_with_back 'leprikon:journal' object.id %}">
                {% trans 'journal' %}
            </a>
            <a class="btn btn-sm btn-primary" href="{% url_with_back 'leprikon:journalentry_create' object.id %}">
                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
                {% trans 'add journal entry' %}
            </a>
        </div>
        {% endif %}
    </div>
</div>

{% include 'leprikon/static/ekko-lightbox.html' %}

{% addtoblock 'js' %}
<script>
<!--
$(document).delegate('*[data-toggle="lightbox"]', 'click', function(event) {
    event.preventDefault();
    $(this).ekkoLightbox();
});
-->
</script>
{% endaddtoblock %}
