{% load i18n %}
{% load translations %}
{% load permissions %}
{% with object.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 'component.lock' project as user_can_lock_component %}


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

<div class="panel panel-default">
<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 info 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 %}
</div>

{% if component %}
<table class="table table-striped">
{% include "snippets/git-info.html" with object=component %}
</table>
{% endif %}
</div>

<div class="panel panel-default">
<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-default">
<div class="panel-heading"><h4 class="panel-title">{% trans "Repository changes" %}</h4></div>
<div class="panel-body">
{% include "last-changes-content.html" with last_changes=changes %}
</div>
</div>

</div>

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

<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-primary" {% 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-primary" 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-primary" {% 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-primary" 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-primary confirm-reset" value="{% trans "Reset" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Reset all changes in the local repository" %}</p>
</td>
</tr>

<tr>
<td>
<form method="POST" action="{{ object.get_cleanup_url }}">
{% csrf_token %}
<input type="submit" class="btn btn-primary confirm-reset" value="{% trans "Cleanup" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Cleanup all untracked files 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-primary" 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-primary" value="{% trans "Lock" %}" />
</form>
</td>
<td>
<p class="helptext">{% trans "Prevent any changes in the local repository" %}</p>
</td>
</tr>
{% endif %}
{% endif %}

</table>

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