{% load i18n %}
{% load parse_date %}
<table id="volumes" class="zebra-striped">
  <tr>
    <th>{% trans "ID" %}</th>
    <th>{% trans "Name" %}</th>
    <th>{% trans "Status" %}</th>
    <th>{% trans "Size" %}</th>
    <th>{% trans "Created" %}</th>
    <th>{% trans "Attached To" %}</th>
    <th>{% trans "Actions" %}</th>
  </tr>
  {% for volume in volumes %}
  <tr class="{% cycle 'odd' 'even' %}">
    <td>{{ volume.id }}</td>
    <td>{{ volume.displayName }}</td>
    <td>{{ volume.status|capfirst }}</td>
    <td>{{ volume.size }} {% trans "GB" %}</td>
    <td>{{ volume.createdAt|parse_date }}</td>
    <td>
      {% for attachment in volume.attachments %}
        {% if attachment %}
          <a href="{% url horizon:nova:instances:detail request.user.tenant_name attachment.serverId %}">
          <!-- TODO (tres): Show instance name -->
          Instance {{ attachment.serverId }}
          <small>({{ attachment.device }})</small>
        </a>
        {% else %}
          {% trans "Not Attached" %}
        {% endif %}
      {% endfor %}
    </td>
    <td id="actions">
      <ul>
        {% if volume.status == "in-use" %}
          {% for attachment in volume.attachments %}
            <li class="form">
              {% include "nova/volumes/_detach.html" with form=detach_form %}
            </li>
          {% endfor %}
        {% endif %}
        {% if volume.status == "available" %}
        <li>
          <a class="btn small" href="{% url horizon:nova:volumes:attach volume.id %}">{% trans "Attach" %}</a>
        </li>
        <li class="form">
          {% include "nova/volumes/_delete.html" with form=delete_form %}
        </li>
        {% endif %}
      </ul>
    </td>
  </tr>
  {% endfor %}
</table>
