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

<table class="table table-autowidth">
{% for change in last_changes %}
<tr class="history-row" {% if in_email %}style="clear:both"{% endif %}>
    <td class="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.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>
    </td>
    <td class="history-data full-cell">
        {% if not in_email %}
        <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 %}
              {% perm 'unit.edit' change.unit as user_can_translate %}
              {% if 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 %}
            {% endif %}
            {% if change.user and not change.user.is_anonymous %}
              {% perm 'project.permissions' change.project as user_can_edit_permissions %}
              {% if change.project and user_can_edit_permissions %}
                <a class="btn btn-link red" href="{% url 'manage-access' project=change.project.slug %}?block_user={{ change.user.username }}#block-user" title="{% trans "Block user" %}">{% icon "account-cancel.svg" %}</a>
              {% endif %}
            {% 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.source_language }}</label>
                {% format_translation change.unit.source change.unit.translation.component.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>
                    {% if change.unit.target == change.target %}
                      <span class="badge">{% trans "Current translation" %}</span>
                    {% endif %}
                </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.source_language }}</label>
                {% format_translation change.unit.source change.unit.translation.component.source_language %}
                <label>{{ change.unit.translation.language }}</label>
                {% format_translation change.target change.unit.translation.language change.unit.translation.plural %}
            {% elif change.show_source %}
                {% format_translation change.target change.component.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 %}
    </td>
</tr>
{% empty %}
<tr>
  <td colspan="2">
    <em>{% trans "No matching activity found." %}</em>
  </td>
</tr>
{% endfor %}
</table>
