{% include 'mixins/partials/notify.html' %}
<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>chat</th>
    <th>identifier</th>
    <th>person</th>
    <th>availability</th>
    <th>actions</th>
  </thead>
  {% for item in object_list %}
    <tr>
      <td>{% if item.is_group %}<span class="tag is-info is-light is-small mr-1"><i class="fa-solid fa-users"></i></span>{% endif %}{{ item.name|default:"WhatsApp Chat" }}</td>
      <td>
        <a
          class="has-text-grey button nowrap-child"
          onclick="window.prompt('Copy to clipboard: Ctrl+C, Enter', '{{ item.identifier }}');">
          <span class="icon" title="Copy identifier" aria-label="Copy identifier">
            <i class="fa-solid fa-copy" aria-hidden="true"></i>
          </span>
        </a>
      </td>
      <td>{{ item.person_name|default:"-" }}</td>
      <td>
        {% if item.availability_label %}
          <span class="tag is-light">{{ item.availability_label }}</span>
        {% else %}
          -
        {% endif %}
      </td>
      <td>
        <div class="buttons">
          {% if type == 'page' %}
            <a href="{{ item.compose_page_url }}" class="button" title="Manual text mode">
              <span class="icon"><i class="fa-solid fa-paper-plane"></i></span>
            </a>
          {% else %}
            <button
              type="button"
              hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
              hx-get="{{ item.compose_widget_url }}"
              hx-trigger="click"
              hx-target="#widgets-here"
              hx-swap="beforeend"
              class="button"
              title="Manual text mode widget">
              <span class="icon"><i class="fa-solid fa-paper-plane"></i></span>
            </button>
          {% endif %}
          <a href="{{ item.match_url }}" class="button" title="Match identifier">
            <span class="icon"><i class="fa-solid fa-link"></i></span>
          </a>
        </div>
      </td>
    </tr>
  {% empty %}
    <tr>
      <td colspan="5" class="has-text-grey">No WhatsApp chats discovered yet.</td>
    </tr>
  {% endfor %}
</table>
