{% extends browser_extends %}

{% load core assets cleanhtml i18n locale common_tags profile_tags %}

{% get_current_language as LANGUAGE_CODE %}
{% get_current_language_bidi as LANGUAGE_BIDI %}

{% block header_content_block %}
<div id="top-stats" class="header">
  {% block header_content %}
  <a id="js-path-summary" href="#">
    <div id="progressbar">
      {% include "browser/_progressbar.html" %}
    </div>
  </a>
  <div class="path-summary-more" id="js-path-summary-more">
    <a id="js-path-summary" class="expand-stats" href="#">
      <i id="js-expand-icon" class="icon-expand-stats"
         title="{% trans 'Expand details' %}"></i>
    </a>
    <div class="path-summary-collapsed">
      {% include 'core/_top_scorers_as_ul.html' %}
    </div>
    <div class="path-summary-expanded">
      <div class="summary-1-col">
        <h3 class="top">{% trans "Translation Statistics" %}</h3>
        <div class="bd">
          <table class="stats" lang="{{ LANGUAGE_CODE }}" dir="{% locale_dir %}">
            <tbody>
              {% for item in translation_states %}
              <tr id="stats-{{ item.state }}">
                <td id="stats-name">{{ item.title }}</td>
                <td class="stats-number">
                  {% if can_translate_stats %}
                  <a href="{{ item.url }}" class="stats-data"></a>
                  {% else %}
                  <span class="stats-data"></span>
                  {% endif %}
                </td>
                <td class="stats-percentage"><span></span>%</td>
              </tr>
              {% endfor %}
            </tbody>
          </table>
        </div>
        <div id="js-stats-checks" class="hide stats-checks">
          <h3>{% trans "Failing Checks" %}</h3>
          <div class="bd">
            <table>
            {% for check in checks %}
              <tr class="{% if check.is_critical %}category-critical{% endif %} check js-check" data-code="{{ check.code }}">
                {% if can_translate_stats %}
                <td class="check-name">
                  <a class="check-data" href="{{ check.url }}">{{ check.title }}</a>
                </td>
                <td class="check-count"><a class="check-data" href="{{ check.url }}">0</a></td>
                {% else %}
                <td class="check-name"><span class="check-data">{{ check.title }}</span></td>
                <td class="check-count"><span class="check-data">0</span></td>
                {% endif %}
              </tr>
            {% endfor %}
            <tr class="js-more-checks">
              <td colspan="2">
                <a class="js-toggle-more-checks toggle-more-checks collapsed">
                  <span class="show-more">{% trans "more..." %}</span>
                  <span class="hide-more">{% trans "less..." %}</span>
                </a>
              </td>
            </tr>
            </table>
          </div>
        </div>
      </div>
      {% if top_scorers %}
        <div class="summary-2-col">
          <h3 class="top">{% trans "Top Contributors for the Last 30 Days" %}</h3>
          <div class="bd">
            {% include 'core/_top_scorers_as_table.html' %}
          </div>
        </div>
      {% endif %}
      <div class="summary-3-col">
        <div id="js-last-updated-wrapper">
          <h3 class="top">{% trans "Updates" %}</h3>
          <div class="bd">
            <div class="graph"></div>
            <div class="action-wrapper">
              <label>{% trans "Last action:" %}</label>
              <div id="js-last-updated" class="last-updated"></div>
            </div>
          </div>
        </div>
        <div id="js-last-action-wrapper">
          <h3>{% trans "Translations" %}</h3>
          <div class="bd">
            <div class="graph"></div>
            <div class="action-wrapper">
              <label>{% trans "Last action:" %}</label>
              <div id="js-last-action" class="last-action"></div>
            </div>
          </div>
        </div>
      </div>
      <div class="clear"></div>
    </div>
  </div>
  {% endblock %}
</div>
{% endblock %}

{% block actions %}
{% include 'browser/_actions.html' %}
{% endblock %}

{% block pre_content %}
{% if has_sidebar %}
<div id="sidebar"
  class="js-sidebar{% if is_sidebar_open %} sidebar-open{% endif %}">
  <div id="sidebar-content">
    {% block sidebar_content %}

    {% if announcements %}
    <div class="sidebar-group">
      {% for announcement in announcements %}
        {% include "staticpages/_body.html" with page=announcement %}
      {% endfor %}
    </div>
    {% endif %}

    {% endblock %}
  </div>
  <a id="sidebar-toggle" class="js-sidebar-toggle"></a>
</div>
{% endif %}

<div id="autorefresh-notice">
  <span>
    {% if user.is_superuser %}
      {% blocktrans trimmed with docs_url="server/rq.html"|docs_url %}
      Stats are out of date.
      See <a href="{{ docs_url }}">documentation</a>
      for dealing with stats issues.
      {% endblocktrans %}
    {% else %}
      {% trans "The stats on this page may be out of date." %}
    {% endif %}
    <a href="#" class="js-stats-refresh">{% trans "Refresh now" %}</a>
    <a href="#" class="js-stats-refresh-close x">×</a>
  </span>
</div>

{% endblock %}

{% block content %}
{% if project and project.disabled %}
<div class="alert alert-danger">
{% trans "This project is disabled and visible to administrators only." %}
</div>
{% endif %}

{% if parent %}
<div class="browser-parent" lang="{{ LANGUAGE_CODE }}">
  <a href="{{ parent.href }}"><i class="icon-folder-parent"></i> <span>{{ parent.title }}</span></a>
</div>
{% endif %}

{% if vfolders %}
<div class="browsing-table-wrapper bd vfolders" lang="{{ LANGUAGE_CODE }}">
  {% display_table vfolders %}
</div>
{% endif %}

{% if table %}
<div class="browsing-table-wrapper bd" lang="{{ LANGUAGE_CODE }}">
  {% display_table table %}
</div>
{% endif %}
{% endblock content %}

{% block scripts_extra %}
{{ block.super }}

<script type="text/javascript">
$(function () {
  PTL.search.init();
  PTL.stats.init({
    pootlePath: "{{ pootle_path }}",
    hasDisabledItems: {{ table.disabled_items|yesno:"true,false" }},
    isAdmin: {{ has_admin_access|yesno:"true,false" }},
    isInitiallyExpanded: {{ is_store|yesno:"true,false" }},
    initialData: {{ stats|to_js }},
    statsRefreshAttemptsCount: {{ stats_refresh_attempts_count }},
    uiLocaleDir: '{{ LANGUAGE_BIDI|yesno:"rtl,ltr" }}',
  });
});
</script>
{% endblock %}
