{% 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 %}

{% perm 'meta:vcs.status' object as user_can_see_repository_status %}
{% perm 'vcs.commit' object as user_can_commit_translation %}
{% perm 'project.permissions' object as user_can_manage_acl %}
{% perm 'project.edit' object as user_can_edit_project %}
{% perm 'component.edit' object as user_can_edit_component %}

<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_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>
      <li role="separator" class="divider"></li>
      {% endif %}
      <li><a href="{% url 'memory' project=object.slug %}">{% trans "Translation memory" %}</a></li>
      {% if user_can_manage_acl %}
      <li><a href="{% url 'manage-access' project=object.slug %}">{% trans "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 components %}
<tr>
<th>
<a href="{{ prj.get_absolute_url }}">{{ prj.name }}</a>
{% if prj.is_repo_link %}<span class="badge pull-right flip tooltip-control" title="{% blocktrans with prj.linked_component as target %}Repository for this component is linked to {{ target }}{% endblocktrans %}">{% trans "link" %}</span>{% endif %}
</th>
<td class="progress-cell">{% translation_progress prj %}</td>
<td class="percent">{{ prj.stats.translated_percent }}%</td>
<td class="progress-cell">{% words_progress prj %}</td>
<td class="percent">{{ prj.stats.translated_words_percent }}%</td>
</tr>
{% empty %}
<tr><td colspan="5">
  {% trans "There are currently no translation components!" as msg %}
  {% show_message "warning" msg %}
</td></tr>
{% endfor %}
</tbody>
{% if user_can_edit_project %}
<tfoot>
<tr><td colspan="5">
  <a class="btn btn-primary project-add-component" href="{% url 'create-component' %}?project={{ object.pk }}">{% trans "Add new translation component" %}</a>
</td></tr>
</tbody>
{% endif %}
</table>

{% include "legend.html" %}

{% with components as page_obj %}
{% include "paginator.html" %}
{% endwith %}

</div>

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

<table class="table table-striped">
{% include "project_info.html" %}
{% if licenses %}
<tr>
<th>{% trans "Translation license" %}</th>
<td colspan="2">{{ licenses }}</td>
</tr>
{% endif %}
{% 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 stats in language_stats %}
<tr>
<th><a href="{% url 'project-language' lang=stats.language.code project=object.slug %}">{{ stats.language.name }}</a></th>
<td class="progress-cell">{% translation_progress stats %}</td>
<td class="percent">{{ stats.translated_percent }}%</td>
<td class="progress-cell">{% words_progress stats %}</td>
<td class="percent">{{ stats.translated_words_percent }}%</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 a string in all strings at once. The search is a 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>

{% if mass_state_form %}
<form action="{% url 'state-change' project=object.slug %}" method="post" enctype="multipart/form-data">
<div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "Mass state change" %}</h4></div>
<div class="panel-body">
<p>{% trans "You can change state of all strings matching given type at once." %}</p>
{% csrf_token %}
{{ mass_state_form|crispy }}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Process" %}" class="btn btn-default" />
</div>
</div>
</form>
{% endif %}

</div>
{% endif %}

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

</div>

{% endblock %}
