{% for mem in memories %}
<tr class="memory-row">
  <td class="col-check">
    <input type="checkbox" class="row-check" value="{{ mem.id }}" onchange="toggleBulkBtn()">
  </td>
  {% if cross_project %}
  <td class="col-project">
    <a href="/memories?project={{ mem.project }}" class="project-link">{{ mem.project }}</a>
  </td>
  {% endif %}
  <td class="col-content" onclick="toggleExpand(this)">
    <div class="content-snippet">{{ mem.content[:150] }}{% if mem.content|length > 150 %}…{% endif %}</div>
    {% if mem.content|length > 150 %}
    <div class="content-full">{{ mem.content }}</div>
    {% endif %}
  </td>
  <td class="col-source">
    <span class="source-text" title="{{ mem.source }}">{{ mem.source[:60] }}{% if mem.source|length > 60 %}...{% endif %}</span>
  </td>
  <td class="col-tags">
    {% for tag in mem.tags %}
    <span class="tag-pill tag-clickable" data-tag="{{ tag }}">{{ tag }}</span>
    {% endfor %}
  </td>
  <td class="col-type">
    <span class="type-badge type-{{ mem.chunk_type }}">{{ mem.chunk_type }}</span>
  </td>
  <td class="col-date">
    <span class="date-text">{{ mem.created_at[:10] if mem.created_at else "" }}</span>
  </td>
  <td class="col-actions">
    <button class="btn btn-icon btn-delete"
            hx-delete="/memories/{{ mem.id }}?project={{ mem.project if cross_project else project }}"
            hx-target="closest tr"
            hx-swap="outerHTML"
            hx-confirm="Delete this memory?"
            title="Delete">
      &times;
    </button>
  </td>
</tr>
{% else %}
<tr>
  <td colspan="{{ 8 if cross_project else 7 }}" class="empty-table">No memories found.</td>
</tr>
{% endfor %}

<!-- OOB swap: update pagination + count outside the tbody -->
<div id="pagination" hx-swap-oob="innerHTML">
  <input type="hidden" name="page" id="page-input" value="{{ page }}">
  {% if page > 1 %}
  <a href="#"
     class="btn btn-ghost"
     hx-get="/memories/table"
     hx-target="#memory-table"
     hx-include="[name]"
     hx-vals='{"page": "{{ page - 1 }}"}'
     >
    &laquo; Prev
  </a>
  {% endif %}
  <span class="page-info">Page {{ page }} of {{ total_pages }}</span>
  {% if page < total_pages %}
  <a href="#"
     class="btn btn-ghost"
     hx-get="/memories/table"
     hx-target="#memory-table"
     hx-include="[name]"
     hx-vals='{"page": "{{ page + 1 }}"}'
     >
    Next &raquo;
  </a>
  {% endif %}
</div>

<span id="memory-count" hx-swap-oob="innerHTML">{{ total }} memories</span>
