{% load i18n %}
{% load translations %}
{% load permissions %}
{% load icons %}

<div class="container-fluid">
{% for change in last_changes %}
<div class="row history-row" {% if in_email %}style="clear:both"{% endif %}>
    <div class="col-xs-2 history-event">
        <strong>{{ change.get_user_display }}</strong>
        <p class="text-muted">{{ change.get_action_display }}</p>
        <p>
            {% if change.project %}
            <a href="{{ change.project.get_absolute_url }}">{{ change.project }}</a>
            {% endif %}
            {% if change.glossary_term %}
            — <a href="{{ change.glossary_term.get_parent_url }}">{{ change.glossary_term.language }}</a>
            {% include "snippets/glossary-badge.html" with glossary=change.glossary_term.glossary %}
            {% endif %}
            {% if change.component %}
            / <a href="{{ change.component.get_absolute_url }}">{{ change.component.name }}</a>
            {% endif %}
            {% if change.translation %}
            — <a href="{{ change.translation.get_absolute_url }}">{{ change.translation.language }}</a>
            {% endif %}
        </p>
    </div>
    <div class="col-xs-10 history-data">
        {% if not in_email %}
        {% perm 'unit.edit' change.unit as user_can_translate %}
        <div class="btn-float pull-right flip">
            <a class="btn btn-link" href="{{ change.get_absolute_url }}" title="{% trans "View details" %}">{% icon "magnify-plus-outline.svg" %}</a>
            {% if debug %}
            <a class="btn btn-link" href="{% url 'show_change' pk=change.pk %}" title="{% trans "View notification" %}">{% icon "bell.svg" %}</a>
            {% endif %}
            {% if change.can_revert and user_can_translate %}
            <a class="btn btn-link" href="{{ change.translation.get_translate_url}}?{% if search_url %}{{ search_url }}&amp;offset={{ offset }}&amp;{% endif %}checksum={{ change.unit.checksum }}&amp;revert={{ change.id }}" title="{% trans "Revert" %}">{% icon "undo.svg" %}</a>
            {% endif %}
        </div>
        {% endif %}
        <div class="comment-content">
            {% with details=change.get_details_display %}
            {% if details %}
                {{ details }}
            {% elif change.can_revert %}
                <label>{{ change.unit.translation.component.project.source_language }}</label>
                {% format_translation change.unit.source change.unit.translation.component.project.source_language %}
                <label>
                    {{ change.unit.translation.language }}
                    {% comment %}Translators: Number of edits on a change in Damerau–Levenshtein distance{% endcomment %}
                    <span class="badge">{% blocktrans count count=change.get_distance %}{{ count }} character edited{% plural %}{{ count }} characters edited{% endblocktrans %}</span>
                </label>
                {% format_translation change.target change.unit.translation.language change.unit.translation.plural diff=change.old %}
            {% elif change.show_content and change.unit %}
                <label>{{ change.unit.translation.component.project.source_language }}</label>
                {% format_translation change.unit.source change.unit.translation.component.project.source_language %}
                <label>{{ change.unit.translation.language }}</label>
                {% format_translation change.target change.unit.translation.language change.unit.translation.plural %}
            {% elif change.show_content and change.glossary_term %}
                {% format_translation change.target change.glossary_term.language  %}
            {% elif change.show_source %}
                {% format_translation change.target change.component.project.source_language diff=change.old %}
            {% elif change.target %}
                <pre>{{ change.target }}</pre>
            {% else %}
                {{ change.get_action_display }}
            {% endif %}
            {% endwith %}
            <span class="pull-right flip text-muted">{{ change.timestamp|naturaltime }}</span>
            <div class="clearfix" {% if in_email %}style="clear:both"{% endif %}></div>
        </div>
        {% if in_email %}
        <a class="button" href="{{ change.get_absolute_url }}">{% trans "View" %}</a>
        {% endif %}
    </div>
</div>
{% empty %}
<p>{% trans "No matching activity found." %}</p>
{% endfor %}
</div>
