{% load umap_tags i18n %}
<table class="maps">
  <thead>
    <tr>
      <th>{% blocktrans %}Name{% endblocktrans %}</th>
      <th>{% blocktrans %}Preview{% endblocktrans %}</th>
      <th>{% blocktrans %}Who can see / edit{% endblocktrans %}</th>
      <th>{% blocktrans %}Last save{% endblocktrans %}</th>
      <th>{% blocktrans %}Owner{% endblocktrans %}</th>
      <th>{% blocktrans %}Actions{% endblocktrans %}</th>
    </tr>
  </thead>
  <tbody>
    {% for map_inst in maps %}
      {% with unique_id="map_"|addstr:map_inst.pk %}
        {{ map_inst.preview_settings|json_script:unique_id }}
        <tr>
          <td>
            <a href="{{ map_inst.get_absolute_url }}">{{ map_inst.name }}</a>
          </td>
          <td>
            <button class="button map-opener neutral" data-map-id="{{ unique_id }}">{% blocktranslate %}Open preview{% endblocktranslate %}</button>
            <dialog>
              <form method="dialog">
                <div id="{{ unique_id }}_target" class="map_fragment"></div>
                <p class="close-dialog">
                  <button class="button" type="submit">Close</button>
                </p>
              </form>
            </dialog>
          </td>
          <td>{{ map_inst.get_share_status_display }} / {{ map_inst.get_edit_status_display }}</td>
          <td>{{ map_inst.modified_at }}</td>
          <td>
            <a href="{{ map_inst.owner.get_url }}">{{ map_inst.owner }}</a>
          </td>
          <td>
            <a href="{{ map_inst.get_absolute_url }}?share">{% translate "Share" %}</a> |
            <a href="{{ map_inst.get_absolute_url }}?edit">{% translate "Edit" %}</a> |
            <a href="{% url 'map_download' map_inst.pk %}">{% translate "Download" %}</a>
          </td>
        </tr>
      {% endwith %}
    {% endfor %}
  </tbody>
</table>
<div class="pagination">
  {% if maps.has_previous %}
    <a href="?p=1{% if q %}&q={{ q }}{% endif %}">« {% translate "first" %}</a>
    <a href="?p={{ maps.previous_page_number }}{% if q %}&q={{ q }}{% endif %}">‹ {% translate "previous" %}</a>
  {% else %}
    {# djlint:off #}
    <span></span>
    <span></span>
    {# djlint:on #}
  {% endif %}

  <span class="current">
    {% blocktranslate with maps_number=maps.number num_pages=maps.paginator.num_pages %}
      Page {{ maps_number }} of {{ num_pages }}
    {% endblocktranslate %}
  </span>

  {% if maps.has_next %}
    <a href="?p={{ maps.next_page_number }}{% if q %}&q={{ q }}{% endif %}">{% translate "next" %} ›</a>
    <a href="?p={{ maps.paginator.num_pages }}{% if q %}&q={{ q }}{% endif %}">{% translate "last" %} »</a>
  {% else %}
    {# djlint:off #}
    <span></span>
    <span></span>
    {# djlint:on #}
  {% endif %}
</div>
