{% load cache %}
{% load cachalot cache %}
{% get_last_invalidation 'core.Message' as last %}
{% include 'mixins/partials/notify.html' %}
{% cache 600 objects_message request.user.id object_list type last %}
  <table
    class="table is-fullwidth is-hoverable"
    hx-target="#{{ context_object_name }}-table"
    id="{{ context_object_name }}-table"
    hx-swap="outerHTML"
    hx-trigger="{{ context_object_name_singular }}Event from:body"
    hx-get="{{ list_url }}">
    <thead>
      <th>id</th>
      <th>session</th>
      <th>ts</th>
      <th>sender</th>
      <th>text</th>
      <th>author</th>
      <th>delivered ts</th>
      <th>read ts</th>
      <th>read service</th>
      <th>read by</th>
      <th>actions</th>
    </thead>
    {% for item in object_list %}
      <tr>
        <td>
          <a
            class="has-text-grey button nowrap-child"
            onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.id }}');">
            <span class="icon" title="Copy to clipboard" aria-label="Copy to clipboard">
              <i class="fa-solid fa-copy" aria-hidden="true"></i>
            </span>
          </a>
        </td>
        <td>{{ item.session }}</td>
        <td>{{ item.ts }}</td>
        <td>
          <a
            class="has-text-grey button nowrap-child"
            onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.sender_uuid }}');">
            <span class="icon" title="Copy to clipboard" aria-label="Copy to clipboard">
              <i class="fa-solid fa-copy" aria-hidden="true"></i>
            </span>
          </a>
        </td>
        <td>{{ item.text }}</td>
        <td>{{ item.custom_author }}</td>
        <td>{{ item.delivered_ts }}</td>
        <td>{{ item.read_ts }}</td>
        <td>{{ item.read_source_service }}</td>
        <td>{{ item.read_by_identifier }}</td>
        <td>
          <div class="buttons">
            <button
              hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
              hx-get="{% url 'message_update' type=type session=item.session.id pk=item.id %}"
              hx-trigger="click"
              hx-target="#{{ type }}s-here"
              hx-swap="innerHTML"
              class="button">
              <span class="icon-text">
                <span class="icon">
                  <i class="fa-solid fa-pencil"></i>
                </span>
              </span>
            </button>
            <button
              hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
              hx-delete="{% url 'message_delete' type=type session=item.session.id pk=item.id %}"
              hx-trigger="click"
              hx-target="#modals-here"
              hx-swap="innerHTML"
              hx-confirm="Are you sure you wish to delete {{ item.id }}?"
              class="button">
              <span class="icon-text">
                <span class="icon">
                  <i class="fa-solid fa-xmark"></i>
                </span>
              </span>
            </button>
          </div>
        </td>
      </tr>
    {% endfor %}

  </table>
{% endcache %}
