{% load utils_extra %}
{% load event_extra %}

<div class="grid">
{% for e in object.get_duplicated %}
    <div class="grid entete-badge">
        <div class="badge-large{% if e.masked %} badge-secondary{% endif %}">
        {{ forloop.counter0|int_to_abc }} 
        </div>

        <ul>
            <li>{{ e|picto_status }} <a href="{{ e.get_absolute_url }}">{{ e.title }}</a></li>
            {% for step in e.chronology_dates %}
                    
                {% if step.data == "created_date" %}<li><em>Création</em> le {{ step.timestamp }} par {{ step.user }}</li>{% endif %}
                {% if step.data == "modified_date" %}<li><em>Dernière modification</em> le {{ step.timestamp }}{% if e.modified_by_user %} par {{ e.modified_by_user.username }}{% else %} par import récurrent{% endif %}</li>{% endif %}
                {% if step.data == "moderated_date" %}<li><em>Dernière modération</em> le {{ step.timestamp }}{% if e.moderated_by_user %} par {{ e.moderated_by_user.username }}{% endif %}</li>{% endif %}
                {% if step.data == "imported_date" %}<li><em>Dernière importation</em> le {{ step.timestamp }}{% if e.imported_by_user %} par {{ e.imported_by_user.username }}{% else %} par import récurrent{% endif %}</li>{% endif %}
            {% endfor %}
            <li>État&nbsp;: 
                {% if e.pure_import %}version fidèle à la source importée{% endif %}
                {% if e.local_version %}<strong>version modifiée localement</strong>{% endif %}
            </li>
        </ul>
            {% with e.get_import_messages as messages %}
            {% if messages|length > 0 %}
                <div class="full-columns">
                <h3>Journaux des modifications d'import</h3>
                <ul>
                    {% for m in messages %}
                        <li>
                            {{ m.date }}, {% if m.message_type %}{{ m.get_message_type_display }}{% endif %}&nbsp;: <a href="{% url 'message' m.pk %}">{{ m.subject }}</a>&nbsp;: <em>{{ m.message }}</em>
                        </li>
                    {% endfor %}
                </ul>
                </div>
            {% endif %}
            {% endwith %}
        </div>
{% endfor %}
</div>

{% for e in object.get_items_comparison %}
    <h3>{% event_field_verbose_name e.key %}</h3>
    {% if e.similar %}
    <div class="comparison-item">
        {% if e.key == "image" %}{% if object.get_duplicated.0.local_image %}<img src="{{ object.get_duplicated.0.get_image_url }}" class="preview" />{% endif %}{% endif %}
        <p>Identique&nbsp;: {% field_to_html e.values e.key %}</p>
    </div>
    {% else %}
    <div class="grid comparison-item">
        {% for i in e.values %}
        <div class="duplicated">
            {% if e.key == "image" %}
                {% with object.get_duplicated|index:forloop.counter0 as event %}
                    {% if event.local_image %}<div><img src="{{ event.get_image_url }}" class="preview" /></div>{% endif %}
                {% endwith %}
            {% endif %}    
            <div class="badge-small">{{ forloop.counter0|int_to_abc }} </div> {% field_to_html i e.key %}
        </div>
        {% endfor %}
    </div>
    {% endif %}
{% endfor %}
