{% extends "base.html" %}
{% load i18n %}
{% load translations %}
{% load permissions %}
{% load crispy_forms_tags %}

{% block breadcrumbs %}
<li><a href="{{ object.get_absolute_url }}">{{ object }}</a></li>

<a class="pull-right flip" href="{{ object.get_widgets_url }}">
<img src="{% url 'widget-image' project=object.slug widget='svg' color='badge' extension='svg' %}" />
</a>
{% endblock %}

{% block content %}

{% whiteboard_messages project=object %}

{% can_see_repository_status user object as user_can_see_repository_status %}
{% can_commit_translation user object as user_can_commit_translation %}
{% can_manage_acl user object as user_can_manage_acl %}
{% can_edit_project user object as user_can_edit_project %}

<ul class="nav nav-pills">
  <li class="active"><a href="#components" data-toggle="tab">{% trans "Components" %}</a></li>
  <li><a href="#languages" data-toggle="tab">{% trans "Languages" %}</a></li>
  <li><a href="#information" data-toggle="tab">{% trans "Information" %}</a></li>
  <li><a href="#glossaries" data-toggle="tab">{% trans "Glossaries" %}</a></li>
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Insights" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
      <li><a href="#history" data-toggle="tab">{% trans "History" %}</a></li>
      <li><a href="#activity" data-toggle="tab" data-load="activity" data-yearly="{% url 'yearly_activity' project=object.slug %}" data-monthly="{% url 'monthly_activity' project=object.slug %}">{% trans "Activity" %}</a></li>
      <li><a href="{% url 'export_stats' project=object.slug %}?format=csv">{% trans "Download statistics (CSV)" %}</a></li>
      <li><a href="{% url 'export_stats' project=object.slug %}?format=json">{% trans "Download statistics (JSON)" %}</a></li>
    </ul>
  </li>
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Tools" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
      <li><a href="#search" data-toggle="tab">{% trans "Search" %}</a></li>
      {% if replace_form %}
      <li><a href="#replace" data-toggle="tab">{% trans "Search and replace" %}</a></li>
      {% endif %}
      <li><a href="{% url 'data_project' project=object.slug  %}">{% trans "Data exports" %}</a></li>
      <li><a href="{% url 'checks' %}?project={{ object.slug }}">{% trans "Failing checks" %}</a></li>
      <li><a href="{% url 'checks' %}?project={{ object.slug }}&amp;ignored=true">{% trans "Ignored checks" %}</a></li>
    </ul>
  </li>
  {% if user_can_manage_acl or user_can_edit_project or user_can_commit_translation or user_can_see_repository_status %}
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Manage" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
      {% if user_can_commit_translation %}
      <li><a href="{{ object.get_commit_url }}" class="link-post">{% trans "Commit" %}</a></li>
      {% endif %}
      {% if user_can_see_repository_status %}
      <li><a href="#repository" data-toggle="tab" data-href="{% url 'git_status_project' project=object.slug %}">{% trans "Repository maintenance" %}</a></li>
      {% endif %}
      {% if user_can_commit_translation or user_can_see_repository_status %}
      <li role="separator" class="divider"></li>
      {% endif %}
      {% if user_can_manage_acl %}
      <li><a href="{% url 'manage-access' project=object.slug %}">{% trans "Manage users" %}</a></li>
      {% endif %}
      {% if user_can_edit_project %}
      <li><a href="{% url 'settings' project=object.slug %}">{% trans "Settings" %}</a></li>
      {% endif %}
    </ul>
  </li>
  {% endif %}
{% if enable_sharing %}
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Share" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
{% with object.get_share_url as share_url and object.get_widgets_url as widgets_url %}
      <li><a href="https://www.facebook.com/sharer.php?u={{ share_url }}">{% trans "Share on Facebook!" %}</a></li>
      <li><a href="https://twitter.com/share?text={% blocktrans %}Translate {{ object }} using %23Weblate at {{ share_url }}!{% endblocktrans %}">{% trans "Tweet this translation!" %}</a></li>
      <li><a href="{% url 'engage' project=object.slug %}">{% trans "Engage page" %}</a></li>
      <li><a href="{{ widgets_url }}">{% trans "Status widgets" %}</a></li>
{% endwith %}
    </ul>
  </li>
{% endif %}
{% with object as project %}
{% include "watch-dropdown.html" %}
{% endwith %}
</ul>

<div class="tab-content">
<div class="tab-pane active" id="components">

<table class="sort table">
<thead>
<tr>
<th>{% trans "Component" %}</th>
<th colspan="2">{% trans "Translated" %}</th>
<th colspan="2">{% trans "Words" %}</th>
</tr>
<tbody>
{% for prj in object.subproject_set.select_related %}
<tr>
<th><a href="{{ prj.get_absolute_url }}">{{ prj.name }}</a></th>
<td class="progress-cell">{% translation_progress prj %}</td>
<td class="percent">{{ prj.get_translated_percent }}%</td>
<td class="progress-cell">{% generic_progress prj.get_words_percent %}</td>
<td class="percent">{{ prj.get_words_percent }}%</td>
</tr>
{% endfor %}
</tbody>
</table>

{% include "legend.html" %}

</div>

<div class="tab-pane" id="information">

<table class="table table-striped">
{% include "project_info.html" %}
{% include "project_stats.html" %}
</table>

</div>
<div class="tab-pane" id="languages">

<table class="sort table">
<thead>
<tr>
<th>{% trans "Language" %}</th>
<th colspan="2">{% trans "Translated" %}</th>
<th colspan="2">{% trans "Words" %}</th>
</tr>
</thead>
<tbody>
{% for language in language_stats %}
<tr>
<th><a href="{% url 'project-language' lang=language.0.code project=object.slug %}">{{ language.0 }}</a></th>
<td class="progress-cell">{% generic_progress language.1 %}</td>
<td class="percent">{{ language.1 }}%</td>
<td class="progress-cell">{% generic_progress language.2 %}</td>
<td class="percent">{{ language.2 }}%</td>
</tr>
{% endfor %}
</tbody>
</table>

</div>

<div class="tab-pane" id="glossaries">

{% if dicts %}
<div class="list-group">
{% for language in dicts %}
<a class="list-group-item" href="{% url 'show_dictionary' project=object.slug lang=language.code %}"><span class="badge">{{ language.dictionary__count }}</span>{{ language }}</a>
{% endfor %}
</div>
{% else %}
<p>{% trans "There are currently no glossaries defined for this project." %}</p>
{% endif %}

<a class="btn btn-default" href="{% url 'show_dictionaries' project=object.slug %}">{% trans "Manage all glossaries" %}</a>

</div>

<div class="tab-pane" id="history">
{% include "last-changes-content.html" %}
<a class="btn btn-default" href="{% url 'changes' %}?{{ last_changes_url }}">{% trans "Browse all project changes" %}</a>
</div>

{% include "activity-tab.html" %}

<div class="tab-pane" id="search">

<form action="{% url 'search' project=object.slug %}" method="GET" data-persist="search-project">
{{ search_form|crispy }}
<input type="submit" value="{% trans "Search" %}" class="btn btn-default" />
</form>

</div>

{% if replace_form %}
<div class="tab-pane" id="replace">
<form action="{% url 'replace' project=object.slug %}" method="post" enctype="multipart/form-data">
<div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "Search and replace" %}</h4></div>
<div class="panel-body">
<p>{% trans "You can replace string in all units at once. The search is simple substring case sensitive search." %}</p>
{% csrf_token %}
{{ replace_form|crispy }}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Process" %}" class="btn btn-default" />
</div>
</div>
</form>
</div>
{% endif %}

{% if user_can_see_repository_status %}
<div class="tab-pane" id="repository">
<p>{% trans "Loading…" %}</p>
</div>
{% endif %}

</div>

{% endblock %}
