{% extends 'base.html' %}
{% block content %}
{% load crispy_forms_tags %}

     <div class="mb-6">
    <a href="{% url 'admin_dashboard' %}" 
       class="inline-block px-4 py-2 border-2 border-gray-800 rounded-xl font-bold text-gray-800 hover:text-gray-900 hover:border-gray-900 transition-colors">
        &larr; Admin Dashboard
    </a>
</div>


<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 mt-8">


    <h2 class="text-3xl font-bold mb-6 text-gray-800 text-center">Subscriber List</h2>

    <div class="overflow-x-auto shadow-lg rounded-lg">
        <table class="min-w-full bg-white divide-y divide-gray-200">
            <thead class="bg-indigo-600">
                <tr>
                    <th class="px-6 py-3 text-left text-xs font-medium text-white uppercase tracking-wider">ID</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-white uppercase tracking-wider">Email</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-white uppercase tracking-wider">Subscribed At</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-white uppercase tracking-wider">Status</th>
                    <th class="px-6 py-3 text-left text-xs font-medium text-white uppercase tracking-wider">Action</th>
                </tr>
            </thead>
            <tbody class="divide-y divide-gray-100">
                {% for subscriber in subscribers %}
                <tr class="hover:bg-gray-50 transition-colors">
                    <td class="px-6 py-4 whitespace-nowrap text-gray-800 font-medium">{{ subscriber.id }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-gray-700">{{ subscriber.email }}</td>
                    <td class="px-6 py-4 whitespace-nowrap text-gray-600">{{ subscriber.subscribed_at|date:"M d, Y H:i" }}</td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        {% if subscriber.is_active %}
                            <span class="text-green-600 font-semibold">✅ Active</span>
                        {% else %}
                            <span class="text-red-600 font-semibold">❌ Inactive</span>
                        {% endif %}
                    </td>
                    <td class="px-6 py-4 whitespace-nowrap">
                        <a href="{% url 'toggle_subscriber' subscriber.id %}" 
                           class="text-indigo-600 hover:text-indigo-800 font-medium">
                           {% if subscriber.is_active %}Deactivate{% else %}Activate{% endif %}
                        </a>
                    </td>
                </tr>
                {% empty %}
                <tr>
                    <td colspan="6" class="text-center py-8 text-gray-400">No subscribers yet.</td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>

</div>

{% endblock %}
