{% load i18n %}
{% load translations %}
{% load permissions %}
{% with object.repo_needs_commit as needs_commit %}

{% perm 'vcs.commit' project as user_can_commit_translation %}
{% perm 'vcs.update' project as user_can_update_translation %}
{% perm 'vcs.push' project as user_can_push_translation %}
{% perm 'vcs.reset' project as user_can_reset_translation %}
{% perm 'translation.delete' project as user_can_remove_translation %}
{% perm 'component.lock' project as user_can_lock_component %}


<div class="row">
<div class="col-md-8">

<div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "Repository status" %}</h4></div>
<div class="panel-body">
{% if needs_commit %}
<div class="alert alert-info" role="alert">{% trans "There are some uncommitted changes!" %}</div>
{% endif %}
{% if changes.0.is_merge_failure %}
<div class="alert alert-danger" role="alert">
<p>{% trans "There has been a merge failure in the repository:" %}</p>
<pre>{{ changes.0.target }}</pre>
<p><a href="{% documentation "faq" "merge" %}">{% trans "Check the FAQ for information on how to resolve this." %}</a></p>
</div>
{% else %}
{% if object.repo_needs_merge %}
<div class="alert alert-warning" role="alert">{% trans "The remote repository needs to be merged!" %}</div>
{% endif %}
{% if object.repo_needs_push %}
<div class="alert alert-warning" role="alert">{% trans "There are some new commits in the local repository." %}</div>
{% endif %}
{% if not needs_commit and not object.repo_needs_merge and not object.repo_needs_push %}
<div class="alert alert-success" role="alert">{% trans "The local repository is up to date." %}</div>
{% endif %}
{% endif %}

{% if object.component_set %}
{% else %}
{% with object.get_last_remote_commit as commit %}
<p>
{% trans "Last remote commit:" %}
{% include "git-commit-info.html" %}
</p>
{% endwith %}
{% with object.get_export_url as export_url %}
{% if export_url %}
<p>
{% trans "Repository containing Weblate translations:" %}
<code class="git-repo ui-corner-all">{{ export_url }}</code>
</p>
{% endif %}
{% endwith %}
{% endif %}
</div>
</div>

<div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "Repository details" %}</h4></div>
      <div class="panel-body">
        {% for status in statuses %}
        {% if status.0 %}
        <h4>{{ status.0 }}</h4>
        {% endif %}
        <pre>{{ status.1 }}</pre>
        {% endfor %}
      </div>
</div>

<div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "Repository changes" %}</h4></div>
      <div class="panel-body">
        <table class="table">
        {% for change in changes %}
        <tr>
        <td>{{ change.timestamp|naturaltime }}</td>
        <td>{{ change.get_user_display }}</td>
        <td>{{ change.get_action_display }}</td>
        <td>
        {% if change.translation %}
            <a href="{{ change.get_translation_url }}">{{ change.translation.language }}</a>
        {% endif %}
        </td>
        </tr>
        {% if change.target %}
        <tr>
        <td colspan="4"><pre>{{ change.target }}</td>
        </tr>
        {% endif %}
        {% endfor %}
        </table>
      </div>
</div>

</div>

<div class="col-md-4">
<div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "Repository tools" %}</h4></div>
<div class="panel-body">

<table class="table table-condensed">

{% if user_can_commit_translation %}
<tr>
<td>
<form method="POST" action="{{ object.get_commit_url }}">
{% csrf_token %}
<input type="submit" class="btn btn-default" {% if not needs_commit %}disabled="disabled"{% endif %} value="{% trans "Commit" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Commit pending changes to the local repository" %}</p>
</td>
</tr>
{% endif %}

{% if user_can_update_translation %}
<tr>
<td>
<form method="POST" action="{{ object.get_update_url }}">
{% csrf_token %}
<input type="submit" class="btn btn-default" value="{% trans "Pull" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Pull changes from the remote repository" %}</p>
</td>
</tr>
{% endif %}

{% if user_can_push_translation %}
<tr>
<td>
<form method="POST" action="{{ object.get_push_url }}">
{% csrf_token %}
<input type="submit" class="btn btn-default" {% if not object.can_push %}disabled="disabled"{% endif %} value="{% trans "Push" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Push changes to the remote repository" %}</p>
</td>
</tr>
{% endif %}

{% if user_can_update_translation %}
<tr>
<td>
<form method="POST" action="{{ object.get_update_url }}?method=rebase">
{% csrf_token %}
<input type="submit" class="btn btn-default" value="{% trans "Rebase" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Rebase local changes onto the remote repository" %}</p>
</td>
</tr>
{% endif %}

{% if user_can_reset_translation %}
<tr>
<td>
<form method="POST" action="{{ object.get_reset_url }}">
{% csrf_token %}
<input type="submit" class="btn btn-default confirm-reset" value="{% trans "Reset" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Reset all changes in the local repository" %}</p>
</td>
</tr>
{% endif %}


{% if user_can_lock_component and object.is_lockable %}
{% if object.locked %}
<tr>
<td>
<form method="POST" action="{{ object.get_unlock_url }}">
{% csrf_token %}
<input type="submit" class="btn btn-default" value="{% trans "Unlock" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Allow changes to the local repository" %}</p>
</td>
</tr>
{% else %}
<tr>
<td>
<form method="POST" action="{{ object.get_lock_url }}">
{% csrf_token %}
<input type="submit" class="btn btn-default" value="{% trans "Lock" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Prevent any changes in the local repository" %}</p>
</td>
</tr>
{% endif %}
{% endif %}

{% if translation and user_can_remove_translation %}
<tr>
<td>
<form method="POST" action="{% url 'remove_translation' project=translation.component.project.slug component=translation.component.slug lang=translation.language.code %}">
{% csrf_token %}
<input type="submit" class="btn btn-danger" value="{% trans "Delete" %}" />
</form>
</td>
<td>
<p class="helptext">{% blocktrans %}Removes current translation from the repository.{% endblocktrans %}</p>
</td>
</tr>
{% endif %}


</table>

</div>

</div>
</div>
{% endwith %}
