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

{% block admin_content %}
  <header class="flex justify-between items-center mb-8">
    <div>
      <h1 class="text-2xl">Audiences</h1>
      <p class="text-sm text-slate mt-1">Resend audiences and contact counts</p>
    </div>
    <a href="{{ url_for('admin.index') }}" class="btn-outline btn-sm">Back to Dashboard</a>
  </header>

  {% if audiences %}
  <div class="grid-2" style="gap:1rem">
    {% for a in audiences %}
    <div class="card" style="padding:1.25rem">
      <div class="flex justify-between items-center mb-2">
        <h2 class="text-lg">{{ a.name }}</h2>
        {% if a.contact_count is not none %}
        <span class="badge">{{ a.contact_count }} contacts</span>
        {% else %}
        <span class="badge text-slate">API unavailable</span>
        {% endif %}
      </div>
      <p class="mono text-xs text-slate mb-3">{{ a.audience_id }}</p>
      <a href="{{ url_for('admin.audience_contacts', audience_id=a.audience_id) }}" class="btn-outline btn-sm">View Contacts</a>
    </div>
    {% endfor %}
  </div>
  {% else %}
  <div class="card text-center" style="padding:2rem">
    <p class="text-slate">No audiences found. They are created automatically when users sign up.</p>
  </div>
  {% endif %}
{% endblock %}
