{% extends "base.html" %}

{% block content %}
<div class="container py-5">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="h2">Campaign Events</h1>
        <div class="d-flex gap-2">
            <a href="{% url 'event_create' %}" class="btn btn-primary btn-sm">+ Create New Event</a>
        </div>
    </div>

    <div class="card border-0 shadow-sm">
        <div class="table-responsive">
            <table class="table table-hover mb-0 align-middle">
                <thead class="bg-light">
                    <tr>
                        <th class="ps-4">Event Name</th>
                        <th>Type</th>
                        <th>Date</th>
                        <th>Time</th>
                        <th>Location</th>
                        <th class="pe-4 text-end">Actions</th>
                    </tr>
                </thead>
                <tbody>
                    {% for event in events %}
                    <tr>
                        <td class="ps-4">
                            <a href="{% url 'event_detail' event.id %}" class="fw-semibold text-primary text-decoration-none d-block">
                                {{ event.name|default:event.event_type }}
                            </a>
                        </td>
                        <td><span class="badge bg-light text-dark border">{{ event.event_type }}</span></td>
                        <td>{{ event.date|date:"M d, Y" }}</td>
                        <td>
                            {% if event.start_time %}
                                {{ event.start_time|time:"g:i A" }}
                                {% if event.end_time %} - {{ event.end_time|time:"g:i A" }}{% endif %}
                            {% else %}
                                -
                            {% endif %}
                        </td>
                        <td>
                            {% if event.city or event.state %}
                                {{ event.city }}{% if event.city and event.state %}, {% endif %}{{ event.state }}
                            {% else %}
                                -
                            {% endif %}
                        </td>
                        <td class="pe-4 text-end">
                            <a href="{% url 'event_detail' event.id %}" class="btn btn-sm btn-outline-primary">View Details</a>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="6" class="text-center py-5 text-muted">
                            <p class="mb-0">No events found for this campaign.</p>
                        </td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}