{% load i18n %}
{% load translations %}
{% load permissions %}
{% load humanize %}
{% load icons %}

{% with needs_commit=object.needs_commit %}

{% perm 'vcs.commit' object as user_can_commit_translation %}
{% perm 'vcs.update' object as user_can_update_translation %}
{% perm 'vcs.push' object as user_can_push_translation %}
{% perm 'vcs.reset' object as user_can_reset_translation %}
{% perm 'component.lock' object as user_can_lock_component %}


<div class="panel panel-default">
<div class="panel-heading">
  <h4 class="panel-title">
    {% documentation_icon 'devel/integration' 'manage-vcs' right=True %}
    {% trans "Repository status" %}
  </h4>
</div>
<table class="table table-autowidth">
  <tr>
    <th class="number">
      {{ pending_units|intcomma }}
    </th>
    <td class="full-cell">
      {% trans "Pending changes not yet committed to the Weblate repository" %}
    </td>
    <td class="number">
      {% if user_can_commit_translation %}

        <a href="" class="btn btn-primary link-post" data-href="{{ object.get_commit_url }}" {% if not pending_units %}disabled="disabled"{% endif %} title="{% trans "Commit pending changes to the Weblate repository" %}">{% trans "Commit" %}</a>
      {% endif %}
    </td>
  </tr>
  <tr>
    <th class="number">
      {{ outgoing_commits|intcomma }}
    </th>
    <td class="full-cell">
      {% trans "Outgoing commits in the Weblate repository" %}
    </td>
    <td class="number">
      {% if user_can_push_translation %}
        <a href="" class="btn btn-primary link-post" data-href="{{ object.get_push_url }}" {% if not object.can_push %}disabled="disabled"{% endif %} title="{% if not object.has_push_configuration %}{% trans "Please configure push URL in the component settings to enable pushing from Weblate." %}{% else %}{% trans "Push changes to the remote repository" %}{% endif %}">{% trans "Push" %}</a>
      {% endif %}
    </td>
  </tr>
  <tr>
    <th class="number">
      {{ missing_commits|intcomma }}
    </th>
    <td class="full-cell">
      {% trans "Missing commits in the Weblate repository" %}
    </td>
    <td class="number">
      {% if user_can_update_translation %}
        <div class="btn-group pull-right flip">
          <a href="" class="btn btn-primary link-post" data-href="{{ object.get_update_url }}" title="{% trans "Update with changes from the remote repository" %}">{% trans "Update" %}</a>
          <button type="button" class="btn btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            <span class="caret"></span>
            <span class="sr-only">Toggle Dropdown</span>
          </button>
          <ul class="dropdown-menu dropdown-menu-right">
            <li>
              <a href="" class="link-post" data-href="{{ object.get_update_url }}?method=merge" title="{% trans "Pull changes from the remote repository" %}">{% trans "Pull" %}</a>
            </li>
            <li>
              <a href="" class="link-post" data-href="{{ object.get_update_url }}?method=rebase" title="{% trans "Rebase Weblate changes onto the remote repository" %}">{% trans "Rebase" %}</a>
            </li>
            <li>
              <a href="" class="link-post" data-href="{{ object.get_update_url }}?method=merge_noff" title="{% trans "Pull changes from the remote repository without fast-forward" %}">{% trans "Merge without fast-forward" %}</a>
            </li>
          </ul>
        </div>
      {% endif %}
    </td>
  </tr>
  {% if object.is_lockable %}
  <tr>
    <th class="number">
      {% if object.locked %}
        {% icon "lock.svg" %}
      {% endif %}
    </th>
    <td>
      {% trans "Locking prevents translators from doing changes" %}
    </td>
    <td class="number">
      {% if user_can_lock_component %}
        {% if object.locked %}
          <a href="" class="btn btn-primary link-post" data-href="{{ object.get_unlock_url }}" title="{% trans "Allow changes to the Weblate repository" %}">{% trans "Unlock" %}</a>
        {% else %}
          <a href="" class="btn btn-primary link-post" data-href="{{ object.get_lock_url }}" title="{% trans "Prevent any changes in the Weblate repository" %}">{% trans "Lock" %}</a>
        {% endif %}
      {% endif %}
    </td>
  </tr>
  {% endif %}
  {% if user_can_reset_translation %}
    <tr>
      <th class="number">
      </th>
      <td>
        {% trans "Resetting removes all changes in Weblate so that the repository matches upstream. Use with caution." %}
      </td>
      <td class="number">
        <div class="btn-group pull-right flip">
          <button type="button" class="btn btn-danger dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
            {% trans "Maintenance" %}
            <span class="caret"></span>
          </button>
          <ul class="dropdown-menu dropdown-menu-right">
            <li>
              <a href="" class="link-post" data-href="{{ object.get_reset_url }}" title="{% trans "Reset all changes in the Weblate repository" %}">{% trans "Reset" %}</a>
            </li>
            <li>
              <a href="" class="link-post" data-href="{{ object.get_cleanup_url }}" title="{% trans "Cleanup all untracked files in the Weblate repository" %}">{% trans "Cleanup" %}</a>
            </li>
            <li>
              <a href="" class="link-post" data-href="{{ object.get_file_sync_url }}" title="{% trans "Force writing all translations to the Weblate repository" %}">{% trans "Force synchronization" %}</a>
            </li>
          </ul>
        </div>
      </td>
    </tr>
  {% endif %}
</table>
</div>

{% for component in repositories %}
  <div class="panel panel-default">
    <div class="panel-heading">
      <h4 class="panel-title">
        {% blocktrans %}Repository for {{ component }}{% endblocktrans %}
      </h4>
    </div>
    <table class="table table-striped table-autowidth">
      {% include "snippets/git-info.html" with object=component %}
      <tr>
        <th>{% trans "Repository details" %}</th>
        <td class="full-cell"><pre>{{ component.repository.status }}</pre></td>
      </tr>
    </table>
  </div>
{% endfor %}

<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>

{% endwith %}
