{% load i18n %}
{% load statistics %}
{% load addons %}
{% load watches %}
{% load submissions %}
{% load permissions %}
{% load webeditortags %}
{% load team_tags %}

{% if stats %}
{% url notification.views.notices as notices_url %}
<table id="stats_comp" class="stats_comp tablesorter">
   <thead>
    <tr>
      <th>{% trans "Language" %}</th>
      <th class="alcenter">{% trans "Translations" %}</th>
      <th>{% trans "Options" %}</th>
    </tr>
   </thead>
   <tbody>
   {% for stat in stats %} 
   {% get_permission "project_perm.submit_file" for request.user and stat as "can_submit_file" %}
      <tr class="{% number_range stat.trans_perc %}"> 
        <td class="left name" id="{{stat.language_code}}">
          {% if stat.language %}
              {% with stat.language as language_obj %}
              {% with language_obj.code|language_has_team:stat.object.project as team %}
              {% if team %}
                <a class="{% if stat.object.project.outsource %}outsource{% endif %}" href="{% url team_detail team.project.slug team.language.code %}" title="{% if stat.object.project.outsource %}{% trans "See the outsource team for this language. You will be redirected to another project team page." %}{% else %}{% trans "See the team for this language" %}{% endif %}">{{language_obj.name}}</a> <span class="stat_message" >(<a href="{{language_obj.get_absolute_url}}" title="{% trans "See statistics for this language" %}">{{language_obj.code}}</a>)</span>
              {% else %}
                <span title="{% trans "No team for this language" %}">{{language_obj.name}}</span> <span class="stat_message" >(<a href="{{language_obj.get_absolute_url}}" title="{% trans "See statistics for this language" %}">{{language_obj.code}}</a>)</span>
              {% endif %}
              {% endwith %}
              {% endwith %}
          {% else %}
              <span class="stat_message" title="{% trans "There are no languages registered matching this code" %}" >{{ stat.language_code }}</span>
          {% endif %}
          {% if stat.error %}
            {% if stat.is_aggregated %}
              <span class="i16 notice" title="{% trans "There is at least one file broken here." %}"></span>
            {% else %}
              <span class="i16 notice" title="{% trans "This PO file is broken. The web editor is disabled for it." %}"></span>
            {% endif %}
          {% endif %}
        </td>
        {% with 140 as barwidth %}
        <td class="stats" style="width: {{ barwidth|add:"2" }}px;">
          <div class="stats_string_comp" title="{% trans "Trans:" %}{{stat.trans}} {% trans "Fuzzy:" %}{{stat.fuzzy}} {% trans "Untrans:" %}{{stat.untrans}}" >{{stat.trans_perc}}% <span class='trans_detail'>({{stat.trans}}/{{stat.fuzzy}}/{{stat.untrans}})</span></div> 
          {% stats_bar_full stat barwidth %}
        </td>
        {% endwith %}
        <td class="left actions">
          {% if stat.is_aggregated %}
            {% url component_language_detail stat.object.project.slug stat.object.slug stat.language_code as comp_lang_url %}
            <a class="i16 multifile nodecoration_icon" href="{{ comp_lang_url }}" title="{% trans "Click here to see the multiple files for" %} {{ stat.language_code }}"></a>
          {% else %}
           {% url component_view_file stat.object.project.slug stat.object.slug stat.filename as file_view_url %}
           {% url component_raw_file stat.object.project.slug stat.object.slug stat.filename as file_raw_url %}
           {% url component_edit_file stat.object.project.slug stat.object.slug stat.filename as file_edit_url %}
           <a class="i16 view nodecoration_icon" title="{% trans "View " %}{{stat.filename}}" href="{{file_view_url}}"></a>
           <a class="i16 get_file nodecoration_icon" title="{% trans "Download for viewing " %}{{stat.filename}}" href="{{file_raw_url}}"></a>

           {% comment %}Temporarily hooks are disabled here, until we improve the compontent detail view{% endcomment %}
           {% load locks_tags %}
           {% pofile_lock stat %}
           {% comment %}{% hook "comp_stats_table.html" extra_buttons %}{% endcomment %}

           {% if notices_url %}
             {% if perms.repowatch.add_watch or can_submit_file %}
                {% watch_toggle stat %}
             {% endif %}
           {% endif %}
           {% if request.user.is_authenticated and stat.object.allows_submission %}
            {% if perms.reviews.add_poreviewrequest or can_submit_file %}
              {% if file_edit_url and stat.total|webtrans_is_under_max and not stat.error %}
                <a class="i16 edit_file nodecoration_icon" title="{% trans "Edit " %}{{stat.filename}}" href="{{file_edit_url}}"></a>
              {% endif %}
              {% pofile_submission stat %}
            {% endif %}
           {% endif %}
          {% endif %} 
        </td>
      </tr>
   {% endfor %}
   </tbody>
</table>
{%  endif %}
