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

{% block breadcrumbs %}
{% path_object_breadcrumbs path_object %}

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

{% block content %}

{% announcements project=object.project %}

{% include "snippets/project/state.html" with object=object.project %}

{% include "snippets/watch-dropdown.html" with project=object %}

{% perm 'project.edit' object as user_can_edit_project %}
{% perm 'reports.view' object as user_can_view_reports %}

<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 "Info" %}</a></li>
    <li><a href="#search" data-toggle="tab">{% trans "Search" %}</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>
          {% if last_announcements %}
          <li><a href="#announcement-history" data-toggle="tab">{% trans "Announcements" %}</a></li>
          {% endif %}
        </ul>
    </li>
    <li class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
        {% trans "Files" %} <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
        <li><a href="{% url 'download' path=object.get_url_path %}?format=zip" title="{% trans "Download for offline translation." %}">{% blocktrans %}Download translation files as ZIP file{% endblocktrans %}</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">
          {% if replace_form %}
              <li><a href="#replace" data-toggle="tab">{% trans "Search and replace" %}</a></li>
          {% endif %}
          {% if bulk_state_form %}
              <li><a href="#bulk-edit" data-toggle="tab">{% trans "Bulk edit" %}</a></li>
          {% endif %}
            <li><a href="{% url 'checks' path=object.get_url_path %}">{% trans "Failing checks" %}</a></li>
        </ul>
    </li>
    {% if user_can_edit_project %}
    <li class="dropdown">
        <a class="dropdown-toggle" data-toggle="dropdown" href="#">
        {% trans "Manage" %} <span class="caret"></span>
        </a>
        <ul class="dropdown-menu">
          <li><a href="#add-category" data-toggle="tab">{% trans "Add new category" %}</a></li>
          <li><a href="{% url 'create-component' %}?project={{ object.project.pk }}&amp;category={{ object.pk }}">{% trans "Add new translation component" %}</a></li>

        {% if delete_form or rename_form %}
        <li role="separator" class="divider"></li>
        <li><a href="#organize" data-toggle="tab">{% trans "Organize or remove" %}</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 share_url=object.project.get_share_url widgets_url=object.project.get_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' path=object.get_url_path %}">{% trans "Engage page" %}</a></li>
        <li><a href="{{ widgets_url }}">{% trans "Status widgets" %}</a></li>
    {% endwith %}
        </ul>
    </li>
    {% endif %}
</ul>

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

{% include "snippets/list-objects.html" with objects=components list_categories=categories name_source="name" label=_("Component") add_link="component-category" %}

{% include "paginator.html" with page_obj=components %}

</div>

<div class="tab-pane" id="information">
  {% include "snippets/info.html" with project=object.project stats=object.stats metrics=object|metrics show_source=True %}
</div>

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

{% include "snippets/list-objects.html" with objects=language_stats name_source="language" label=_("Language") project=object global_base=object.stats %}

</div>

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

{% if last_announcements %}
<div class="tab-pane" id="announcement-history">
{% include "last-changes-content.html" with last_changes=last_announcements %}
<a class="btn btn-primary" href="{% url 'changes' path=object.get_url_path %}?action=46">{% trans "Browse all project changes" %}</a>
</div>
{% endif %}

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

<form action="{% url 'search' path=object.get_url_path %}" method="GET" data-persist="search-project">
{% include "snippets/search-form.html" %}
</form>

</div>

{% if replace_form %}
<div class="tab-pane" id="replace">
<form action="{% url 'replace' path=object.get_url_path %}" method="post" enctype="multipart/form-data">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">
  {% documentation_icon 'user/translating' 'search-replace' right=True %}
  {% trans "Search and replace" %}
</h4></div>
<div class="panel-body">
{% crispy replace_form %}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Replace" %}" class="btn btn-primary" />
</div>
</div>
</form>
</div>
{% endif %}

{% if bulk_state_form %}
<div class="tab-pane" id="bulk-edit">
<form action="{% url 'bulk-edit' path=object.get_url_path %}" method="post" enctype="multipart/form-data">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">
  {% documentation_icon 'user/translating' 'bulk-edit' right=True %}
  {% trans "Bulk edit" %}
</h4></div>
<div class="panel-body">
{% crispy bulk_state_form %}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Apply" %}" class="btn btn-primary" />
</div>
</div>
</form>
</div>
{% endif %}



{% if user_can_edit_project %}
<div class="tab-pane" id="add-category">

<form method="post" action="{% url 'add-category' path=object.get_url_path %}">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Add a category" %}</h4></div>
<div class="panel-body">
<div class="form-group">
</div>
{% crispy add_form %}
</div>
<div class="panel-footer">
<input type="submit" class="btn btn-warning" value="{% trans "Add" %}">
</div>
</div>
</form>

</div>
{% endif %}

{% if rename_form or delete_form %}
<div class="tab-pane" id="organize">

{% if rename_form %}
<form method="post" action="{% url 'rename' path=object.get_url_path %}">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Rename category" %}</h4></div>
<div class="panel-body">
<div class="form-group">
  <div class="alert alert-warning" role="alert">
    {% trans "Renaming the category will also change URLs for all its components." %}
    {% trans "Users will need to update their bookmarks, references in cloned repositories, or API calls!" %}
  </div>
</div>
{% crispy rename_form %}
</div>
<div class="panel-footer">
<input type="submit" class="btn btn-warning" value="{% trans "Rename" %}">
</div>
</div>
</form>

<form method="post" action="{% url 'move' path=object.get_url_path %}">
<div class="panel panel-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Move category" %}</h4></div>
<div class="panel-body">
<div class="form-group">
  <div class="alert alert-warning" role="alert">
    {% trans "Moving the category will also change URLs for all its components." %}
    {% trans "Users will need to update their bookmarks, references in cloned repositories, or API calls!" %}
  </div>
</div>
{% crispy move_form %}
</div>
<div class="panel-footer">
<input type="submit" class="btn btn-warning" value="{% trans "Move" %}">
</div>
</div>
</form>
{% endif %}

{% if delete_form %}
{% include "trans/delete-form.html" %}
{% endif %}

</div>
{% endif %}

</div>

{% endblock %}
