{% comment %}
# SPDX-License-Identifier: AGPL-3.0-or-later
{% endcomment %}

{% load i18n %}
{% load extras %}

<div class="table-responsive repository" data-repository-name="{{ repository.name }}">
  <table class="table" class="archives-list">
    <thead>
      <tr>
        <th colspan="2">
          <div  class="d-sm-flex flex-sm-row">
            <div class="flex-sm-grow-1 lh-lg collapsible-button"
                 data-bs-toggle="collapse" data-bs-target="#{{ uuid }}">
              {% icon 'chevron-right' %}
              {% if repository.error %}
                <span title={{ repository.error }}>
                  {% icon 'exclamation-triangle' %}</span>
              {% elif repository.is_encrypted %}
                <span title="{% trans "This repository is encrypted" %}">
                  {% icon 'lock' class='svg-icon encrypted' %}
                </span>
              {% endif %}

              <span class="repository-name">{{ repository.name }}</span>
            </div>

            <div class="text-end">
              <a class="repository-schedule btn btn-sm btn-primary"
                 href="{% url 'backups:schedule' uuid %}">
                {% icon 'clock-o' %}
                {% trans "Schedule" %}
              </a>

              {% if repository.flags.mountable %}

                {% if repository.mounted %}

                  <form action="{% url 'backups:repository-umount' uuid %}" method="POST"
                        class="inline-block" >
                    {% csrf_token %}
                    <button type="submit" class="btn btn-sm btn-default"
                           title="{% trans 'Unmount Location' %}">
                      {% icon 'eject' %}
                    </button>
                  </form>

                {% else %}

                  <form action="{% url 'backups:repository-mount' uuid %}" method="POST"
                        class="inline-block" >
                    {% csrf_token %}
                    <button type="submit" class="btn btn-sm btn-default"
                            title="{% trans 'Mount Location' %}">
                      {% icon 'eye' %}
                    </button>
                  </form>

                {% endif %}

              {% endif %}

              {% if repository.flags.removable %}

                <a title="{% trans 'Remove Backup Location. This will not delete the remote backup.' %}"
                   role="button" class="repository-remove btn btn-sm btn-default"
                   href="{% url 'backups:repository-remove' uuid %}">
                  {% icon 'trash-o' %}
                </a>

              {% endif %}
            </div>
          </div>
        </th>
      </tr>
    </thead>

    <tbody class="collapse show" id="{{ uuid }}">
      {% if repository.mounted %}

        {% for archive in repository.archives %}
          <tr id="archive-{{ archive.name }}" class="archive">
            <td class="archive-name">{{ archive.name }}</td>
            <td class="archive-operations">
              <a class="archive-export btn btn-sm btn-default"
                 href="{% url 'backups:download' uuid archive.name %}">
                {% trans "Download" %}
              </a>
              <a class="archive-export btn btn-sm btn-default"
                 href="{% url 'backups:restore-archive' uuid archive.name %}">
                {% trans "Restore" %}
              </a>
              <a class="archive-delete btn btn-sm btn-default"
                 href="{% url 'backups:delete' uuid archive.name %}">
                {% icon 'trash-o' %}
              </a>
            </td>
          </tr>
        {% endfor %}

        {% if repository.error %}
          <tr>
            <td>
              <p>{{ repository.error }}</p>
            </td>
          </tr>
        {% endif %}

        {% if not repository.error and not repository.archives %}
          <tr>
            <td>
              <p>{% trans 'No archives currently exist.' %}</p>
            </td>
          </tr>
        {% endif %}

      {% endif %}
    </tbody>
  </table>
</div>
