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

{% init_unique_row_id %}

{% if objects %}
<table class="sort table progress-table autocolspan table-listing">
<thead>
<tr>
<th class="sort-skip"></th>
<th>{{ label|default:_("Project") }}</th>
<th class="number">{% trans "Translated" %}</th>
{% if global_base %}
<th class="number zero-width-1000">{% trans "Strings of total" %}</th><!-- TODO: Rename? -->
{% endif %}
<th class="number zero-width-640">{% trans "Untranslated" %}</th>
<th class="number zero-width-720">{% trans "Untranslated words" %}</th>
<th class="number zero-width-768">{% trans "Checks" %}</th>
<th class="number zero-width-900">{% trans "Suggestions" %}</th>
<th class="number zero-width-1000">{% trans "Comments" %}</th>
</tr>
</thead>


<tbody>
{% for object in objects %}
{% get_translate_url object as translate_url %}
{% get_browse_url object as browse_url %}
{% get_unique_row_id object as row_id %}
<tr id="{{ row_id }}">
<td class="actions" rowspan="2">
{% if object.is_ghost %}
    <form action="{% url 'new-language' project=object.component.project.slug component=object.component.slug %}" method="post">
        {% csrf_token %}
        <input type="hidden" name="lang" value="{{ object.language.code }}" />
        <button type="submit" alt="{% trans "Create translation" %}" title="{% trans "Create translation" %}" class="btn btn-link green">{% icon "plus.svg" %}</button>
    </form>
{% else %}
    {% if translate_url %}
        <a href="{{ translate_url }}{% if object.stats.todo %}?q=state:&lt;translated{% endif %}" class="btn btn-link green" title="{% trans "Translate" %}" alt="{% trans "Translate" %}">{% icon "pencil.svg" %}</a>
    {% else %}
        <a href="{{ browse_url }}" class="btn btn-link green" title="{% trans "Browse" %}" alt="{% trans "Browse" %}">{% icon "folder-search-outline.svg" %}</a>
    {% endif %}
{% endif %}
</td>
<th class="object-link">
{% if object.is_ghost %}
    <span class="ghost">
    {% if name_source == "language" %}
        {{ object.language }}
    {% elif name_source == "component_name" %}
        {{ object.component.name }}
    {% elif name_source == "name" %}
        {{ object.name }}
    {% elif name_source == "language" %}
        {{ object.language }}
    {% elif name_source == "project" %}
        {{ object.project }}
    {% else %}
        {{ object }}
    {% endif %}
    </span>
{% elif name_source == "translation" %}
    <a href="{{ object.component.project.get_absolute_url }}">{{ object.component.project.name }}</a>/<a href="{{ object.component.get_absolute_url }}">{{ object.component.name }}</a>
    — <a class="tail" href="{{ browse_url }}">{{ object.language }}</a>
{% else %}
    <a href="{{ browse_url }}">{% spaceless %}
    {% if name_source == "language" %}
        {{ object.language }}
    {% elif name_source == "component_name" %}
        {{ object.component.name }}
    {% elif name_source == "name" %}
        {{ object.name }}
    {% elif name_source == "language" %}
        {{ object.language }}
    {% elif name_source == "project" %}
        {{ object.project }}
    {% else %}
        {{ object }}
    {% endif %}
    {% endspaceless %}</a>
{% endif %}
{% indicate_alerts object %}
</th>
{% include "snippets/list-objects-percent.html" with percent=object.stats.translated_percent value=object.stats.translated all=object.stats.all %}
{% if global_base %}
    {% global_stats object object.stats global_base as global_stats %}
    {% include "snippets/list-objects-percent.html" with percent=global_stats.translated_percent value=global_stats.translated all=global_stats.all class="zero-width-1000" %}
{% endif %}
{% include "snippets/list-objects-number.html" with value=object.stats.todo query="q=state:<translated" class="zero-width-640" %}
{% include "snippets/list-objects-number.html" with value=object.stats.todo_words query="q=state:<translated" class="zero-width-720" %}
{% include "snippets/list-objects-number.html" with value=object.stats.allchecks query="q=has:check" class="zero-width-768" %}
{% include "snippets/list-objects-number.html" with value=object.stats.suggestions query="q=has:suggestion#suggestions" class="zero-width-900" %}
{% include "snippets/list-objects-number.html" with value=object.stats.comments query="q=has:comment#comments" class="zero-width-1000" %}
</tr>
<tr data-parent="{{ row_id }}">
<td colspan="{% if global_base %}8{% else %}7{% endif %}" class="progress-row autocolspan">{% translation_progress object.stats %}</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p class="text-muted">{% trans "Nothing to list here." %}</p>
{% endif %}
