{% extends "admin/base_admin.html" %}
{% set admin_page = "inbox" %}
{% block title %}Inbox - Email Hub - Admin - {{ config.APP_NAME }}{% endblock %}

{% block admin_content %}
  <header class="flex justify-between items-center mb-8">
    <div>
      <h1 class="text-2xl">Inbox</h1>
      <p class="text-sm text-slate mt-1">
        {{ messages | length }} messages shown
        {% if unread_count %}&middot; <strong>{{ unread_count }} unread</strong>{% endif %}
      </p>
    </div>
    <a href="{{ url_for('admin.email_compose') }}" class="btn btn-sm">+ Compose</a>
  </header>

  {% if messages %}
  <div class="card">
    <table class="table">
      <thead>
        <tr>
          <th></th>
          <th>From</th>
          <th>Subject</th>
          <th>Received</th>
        </tr>
      </thead>
      <tbody>
        {% for m in messages %}
        <tr{% if not m.is_read %} style="font-weight:600"{% endif %}>
          <td style="width:24px">
            {% if not m.is_read %}
            <span style="display:inline-block;width:8px;height:8px;border-radius:50%;background:#1D4ED8" title="Unread"></span>
            {% endif %}
          </td>
          <td class="text-sm" style="max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">
            <a href="{{ url_for('admin.inbox_detail', msg_id=m.id) }}">{{ m.from_addr }}</a>
          </td>
          <td class="text-sm" style="max-width:300px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">
            <a href="{{ url_for('admin.inbox_detail', msg_id=m.id) }}">{{ m.subject or '(no subject)' }}</a>
          </td>
          <td class="mono text-sm">{{ m.received_at[:16] if m.received_at else '-' }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
  {% else %}
  <div class="card text-center" style="padding:2rem">
    <p class="text-slate">No inbound emails yet.</p>
  </div>
  {% endif %}
{% endblock %}
