{% set admin_page = "waitlist" %}
{% extends "admin/base_admin.html" %}

{% block title %}Waitlist - {{ config.APP_NAME }} Admin{% endblock %}
{% block topbar_title %}Waitlist{% endblock %}

{% block admin_content %}
  <div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:20px;">
    <div>
      <h2 class="text-xl" style="margin:0;">Waitlist</h2>
      <p class="text-sm text-stone" style="margin:4px 0 0;">
        {{ total }} {% if total == 1 %}person{% else %}people{% endif %} waiting
        {% if not config.WAITLIST_MODE %}
        &middot; <span style="color:#15803D;font-weight:600;">Waitlist mode is OFF</span>
        {% else %}
        &middot; <span style="color:#D97706;font-weight:600;">Waitlist mode is ACTIVE</span>
        {% endif %}
      </p>
    </div>
  </div>

  <div class="card" style="padding:0;overflow:hidden;">
    {% if entries %}
    <table class="table">
      <thead>
        <tr>
          <th>Email</th>
          <th>Intent</th>
          <th>Plan</th>
          <th>Source</th>
          <th>IP</th>
          <th>Joined</th>
        </tr>
      </thead>
      <tbody>
        {% for entry in entries %}
        <tr>
          <td>{{ entry.email }}</td>
          <td><span class="badge">{{ entry.intent }}</span></td>
          <td>
            {% if entry.plan %}
            <span class="badge-success">{{ entry.plan }}</span>
            {% else %}
            <span class="text-stone text-xs">&mdash;</span>
            {% endif %}
          </td>
          <td class="text-sm text-stone">{{ entry.source or '&mdash;' }}</td>
          <td class="mono text-sm text-stone">{{ entry.ip_address or '&mdash;' }}</td>
          <td class="mono text-sm">{{ entry.created_at[:16] }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
    {% else %}
    <div style="padding:40px;text-align:center;">
      <p class="text-stone text-sm">No waitlist entries yet.</p>
      {% if not config.WAITLIST_MODE %}
      <p class="text-xs text-stone mt-2">Set <code>WAITLIST_MODE=true</code> to enable the waitlist gate on /auth/signup.</p>
      {% endif %}
    </div>
    {% endif %}
  </div>
{% endblock %}
