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

{% if stats %}
{% url notification.views.notices as notices_url %}
<table id="stats_comp_lang" class="stats_comp tablesorter">
   <thead>
    <tr>
      <th>{% trans "Files" %}</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.filename}}">
              <span class="stat_message">{{stat.filename}}</span>
          {% 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">
           {% 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 %}
        </td>
      </tr>
   {% endfor %}
   </tbody>
</table>
{%  endif %}
