{% extends "agenda_culturel/page.html" %}

{% block title %}{% block og_title %}{{ object.name }}{% endblock %}{% endblock %}

{% load tag_extra %}
{% load utils_extra %}
{% load cat_extra %}
{% load static %}
{% load cache %}
{% load l10n %}

{% block entete_header %}
    {% css_categories %}
    <script src="/static/admin/js/vendor/jquery/jquery.js"></script>
    <script src="/static/admin/js/jquery.init.js"></script>
    <script src="{% static 'location_field/leaflet/leaflet.js' %}"></script>
    <link href="{% static 'location_field/leaflet/leaflet.css' %}" type="text/css" media="all" rel="stylesheet">
{% endblock %}

{% block fluid %}{% endblock %}

{% block body-class %}place{% endblock %}
{% block content %}

<article>
    <header>
        {% if perms.agenda_culturel.change_place %}
        <a href="{% url 'view_places' %}" role="button">&lt; Tous les lieux</a>    
        {% endif %}
        {% if perms.agenda_culturel.change_place %}
        <div class="slide-buttons">
            <a href="{% url 'edit_place' object.pk %}" role="button">Modifier {% picto_from_name "edit-3" %}</a>
            <a href="{% url 'delete_place' object.pk %}" role="button">Supprimer {% picto_from_name "trash-2" %}</a>
        </div>
        {% endif %}
        <h1>{{ object.name }}</h1>
    </header>
    <div class="grid">
        <div>
            <ul>
                <li><strong>Adresse&nbsp;:</strong> {{ object.address }}, {{ object.city }}</li>
                <li><strong>Coordonnée GPS&nbsp;:</strong> <a href="geo:{{ object.location|tocoords }}">{{ object.location|tocoords }}</a></li>
                {% with object.nb_events_future as nb %}
                    {% if nb > 0 %}
                    <li>{{ nb }} événement{{ nb|pluralize }} à venir</li>
                    {% else %}
                        <li><em>Aucun événement à venir</em></li>
                    {% endif %}
                {% endwith %}
            </ul>

            {% if object.description and not object.description|html_vide %}
            <h2>Description du lieu</h2>
            {{ object.description|safe  }}
            {% endif %}

            {% with object.organisation_set.all as organisations %}
                {% if organisations|length == 1 %}
                <p>L'organisme <a href="{{ organisations.0.get_absolute_url }}">{{ organisations.0 }}</a> organise régulièrement des événements dans ce lieu.</p>
                {% endif %}
                {% if organisations|length > 1 %}
                <p>Les organismes suivants utilisent régulièrement ce lieu&nbsp;:</p>
                <ul>
                    {% for o in organisations %}
                        <li><a href="{{ o.get_absolute_url }}">{{ o }}</a></li>
                    {% endfor %}
                </ul>
                {% endif %}

            {% endwith %}


        </div>
        <div>
            <div id="map_location" style="width: 100%; aspect-ratio: 16/16"></div>
            <script>
                L.Icon.Default.imagePath = "{% static "location_field/leaflet/images/" %}";
                var map = L.map('map_location').setView([{{ object.location|tocoords }}], 13);
                L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
                    maxZoom: 19,
                    attribution: '&copy; <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
                }).addTo(map);
                var marker = L.marker([{{ object.location|tocoords }}]).addTo(map);
            </script>
            <p>Voir aussi <a href="{% url 'view_places' %}">les autres lieux</a></p>
        </div>
    </div>
    {% with cache_timeout=user.is_authenticated|yesno:"30,600" %}
    {% cache cache_timeout place_list user.is_authenticated object page_obj.number past %}
    <div class="slide-buttons">
        {% if past %}
        <a href="{{ object.get_absolute_url }}" role="button">Voir les événements à venir</a>
        {% else %}
        <a href="{% url 'view_place_past' object.pk %}" role="button">Voir les événements passés</a>
        {% endif %}
    </div>
    {% if past %}
    <h2>Événements passés</h2>
    {% else %}
    <h2>Événements à venir</h2>
    {% endif %}
    {% if object_list %}

        {% include "agenda_culturel/navigation.html" with page_obj=page_obj %}

        {% for event in object_list %}
            {% include "agenda_culturel/single-event/event-elegant-inc.html" with event=event day=0 no_location=1 %}
        {% endfor %}

        {% include "agenda_culturel/navigation.html" with page_obj=page_obj %}

    {% endif %}
    {% endcache %}
    {% endwith %}
    <footer>
        <!--p>Voir tous les événements de ce lieu</p-->
        {% if user.is_authenticated %}
        {% if object.aliases|length > 0 %}
            <p>Alias associés à ce lieu&nbsp;:</p>
            <ul>
            {% for alias in object.aliases %}
                <li>{{ alias }}</li>
            {% endfor %}
            </ul>
        {% else %}
            <p><em>Ce lieu n'a pas d'alias défini</em></p>
        {% endif %}
    {% endif %}

    </footer>    
</article>

{% endblock %}