{% extends 'main.html' %}
{% block title %} - Raffle Entries{% endblock %}
{% block content %}

<div class="container-fluid mt-4">

<div class="container mt-4"></div>
    <div class="row">
        <!--div class="col-lg-12 mx-auto"-->
        <div class="col-lg-11 mx-auto">
            <div class="card shadow-sm">
                <div class="card-header">
                    <h3><i class="bi bi-trophy-fill text-warning"></i> Fish Raffle Dashboard</h3>
                </div>
                <div class="card-body px-4 py-3">    

                    <div class="d-flex justify-content-between align-items-center mb-3">
                        <h3><i class="bi bi-list-ul"></i> Raffle Entries
                        <span class="badge bg-light text-secondary fs-6 ms-1">{{ entry_count }}</span>
                        </h3>
                        <div class="d-flex gap-2">
                        <a href="{% url 'raffle_export_entries' %}" class="btn btn-outline-secondary btn-sm">
                            <i class="bi bi-download"></i> Export CSV
                        </a>
                        <a href="{% url 'raffle_dashboard' %}" class="btn btn-outline-primary btn-sm">
                            <i class="bi bi-trophy-fill"></i> Back to Dashboard
                        </a>
                        </div>
                    </div>

                    {% if entries %}
                        <div class="table-responsive">
                            <table class="table table-sm table-hover table-bordered align-middle">
                            <thead class="table-dark">
                                <tr>
                                <th>Name</th>
                                <th>Email</th>
                                <th>Username</th>
                                <th>Species Choices</th>
                                <th>Winner For</th>
                                <th>Account Created</th>
                                </tr>
                            </thead>
                            <tbody>
                                {% for e in entries %}
                                <tr {% if e.winner_for %}class="table-success"{% endif %}>
                                <td>{{ e.first_name }} {{ e.last_name }}</td>
                                <td class="small">{{ e.email }}</td>
                                <td class="small">{{ e.proposed_username }}</td>
                                <td class="small">
                                    {% if e.species_1 %}<span class="badge bg-light text-dark me-1">{{ e.species_1 }}</span>{% endif %}
                                    {% if e.species_2 %}<span class="badge bg-light text-dark me-1">{{ e.species_2 }}</span>{% endif %}
                                    {% if e.species_3 %}<span class="badge bg-light text-dark me-1">{{ e.species_3 }}</span>{% endif %}
                                </td>
                                <td>
                                    {% if e.winner_for %}
                                    <span class="badge bg-success">{{ e.winner_for }}</span>
                                    {% else %}
                                    <span class="text-muted small">—</span>
                                    {% endif %}
                                </td>
                                <td class="text-center">
                                    <form method="POST" action="{% url 'raffle_mark_account_created' e.email %}"
                                        style="display:inline;">
                                    {% csrf_token %}
                                    <button type="submit"
                                            class="btn btn-sm {% if e.account_created == 'Yes' %}btn-success{% else %}btn-outline-secondary{% endif %}"
                                            title="Toggle account created">
                                        {% if e.account_created == 'Yes' %}
                                        <i class="bi bi-check-lg"></i> Yes
                                        {% else %}No{% endif %}
                                    </button>
                                    </form>
                                </td>
                                </tr>
                                {% endfor %}
                            </tbody>
                            </table>
                        </div>
                    {% else %}
                        <p class="text-muted">No entries yet.</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>        
</div>
{% endblock %}