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

{% can_commit_translation user project as user_can_commit_translation %}
{% can_update_translation user project as user_can_update_translation %}
{% can_push_translation user project as user_can_push_translation %}
{% can_reset_translation user project as user_can_reset_translation %}
{% can_lock_subproject user project as user_can_lock_subproject %}


<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 not committed changes!" %}</div>
{% endif %}
{% if changes.0.is_merge_failure %}
<div class="alert alert-danger" role="alert">
<p>{% trans "There has been a merge failure on the repository:" %}</p>
<pre>{{ changes.0.target }}</pre>
<p><a href="{% documentation "faq" "merge" %}">{% trans "Check our FAQ for information 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.subproject_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 "Git repository with 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>
<a href="{{ object.get_commit_url }}" class="btn btn-default{% if not needs_commit %} disabled{% endif %}">{% trans "Commit" %}</a>
</td>
<td>
<p class="helptext">{% trans "Commit pending changes to the local repository" %}</p>
</td>
</tr>
{% endif %}

{% if user_can_update_translation %}
<tr>
<td>
<a href="{{ object.get_update_url }}" class="btn btn-default">{% trans "Pull" %}</a>
</td>
<td>
<p class="helptext">{% trans "Pull changes from the remote repository" %}</p>
</td>
</tr>
{% endif %}

{% if user_can_push_translation %}
<tr>
<td>
<a href="{{ object.get_push_url }}" class="btn btn-default{% if not object.can_push %} disabled{% endif %}">{% trans "Push" %}</a>
</td>
<td>
<p class="helptext">{% trans "Push changes to the remote repository" %}</p>
</td>
</tr>
{% endif %}

{% if user_can_update_translation %}
<tr>
<td>
<a href="{{ object.get_update_url }}?method=rebase" class="btn btn-default">{% trans "Rebase" %}</a>
</td>
<td>
<p class="helptext">{% trans "Rebase local changes onto the remote repository" %}</p>
</td>
</tr>
{% endif %}

{% if user_can_reset_translation %}
<tr>
<td>
<a href="{{ object.get_reset_url }}" class="btn btn-default confirm-reset">{% trans "Reset" %}</a>
</td>
<td>
<p class="helptext">{% trans "Reset all changes in the local repository" %}</p>
</td>
</tr>
{% endif %}


{% if user_can_lock_subproject and object.is_lockable %}
{% if object.locked %}
<tr>
<td>
<a href="{{ object.get_unlock_url }}" class="btn btn-default">{% trans "Unlock" %}</a>
</td>
<td>
<p class="helptext">{% trans "Allow changes in the local repository" %}</p>
</td>
</tr>
{% else %}
<tr>
<td>
<a href="{{ object.get_lock_url }}" class="btn btn-default">{% trans "Lock" %}</a>
</td>
<td>
<p class="helptext">{% trans "Prevent any changes in the local repository" %}</p>
</td>
</tr>
{% endif %}
{% endif %}


</table>

</div>

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