{% 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">
      {% progress_bar stats.total stats.fuzzy stats.translated %}
    </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">{{ item.count }}</a>
                  {% else %}
                  <span class="stats-data">{{ item.count }}</span>
                  {% endif %}
                </td>
                <td class="stats-percentage"><span>{{ item.percent }}</span>%</td>
              </tr>
              {% endfor %}
            </tbody>
          </table>
        </div>
        <div id="js-stats-checks" class="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 }}">{{ check.count }}</a></td>
                {% else %}
                <td class="check-name"><span class="check-data">{{ check.title }}</span></td>
                <td class="check-count"><span class="check-data">{{ check.count }}</span></td>
                {% endif %}
              </tr>
            {% endfor %}
            </table>
            <div class="js-more-checks toggle-more-checks">
              <a class="js-toggle-more-checks collapsed">
                <span class="show-more">{% trans "More..." %}</span>
                <span class="hide-more">{% trans "Less..." %}</span>
              </a>
            </div>
          </div>
        </div>
      </div>

      <div id="js-mnt-top-contributors"></div>

      <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 last-action">
		<span class="extra-item-meta">{{ stats.lastupdated.at }}</span>
		<a href="{{ stats.lastupdated.unit_url }}">{{ stats.lastupdated.source }}</a>
	      </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">
		<a href="{{ stats.lastaction.profile_url }}"><img src="{{ stats.lastaction.grav }}" class="avatar" /></a>
		{{ stats.lastaction.msg }} <span class="extra-item-meta">{{ stats.lastaction.at }}</span>
	      </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 %}
{% 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 can_translate %}
</div>
{% endif %}

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

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

<script type="text/javascript">
  $(function () {

  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" }},
    topContributorsData: {{ top_scorers_data|to_js }},
    uiLocaleDir: '{{ LANGUAGE_BIDI|yesno:"rtl,ltr" }}',
  });
});
</script>
{% endblock %}
