{% extends "crm/base.html" %}

{% load static %}

{% block content %}
<div class="container bubble">
    <h2>Prospects</h2>

    <div class="">
        <div class="">

            <form method="get" class="filter-form">
                {% for field in filter.form %}
                <div class="filter-group">
                    <label class="filter-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
                    {{ field }}
                </div>
                {% endfor %}
                <div class="filter-buttons">
                    <button type="submit" class="btn btn-primary">Filter</button>
                    <a href="{% url 'crm:prospect-list' %}" class="btn btn-secondary">Clear</a>
                </div>
            </form>
        </div>
    </div>

    <!-- <div class="mb-3">
        <a href="{% url 'crm:csv-import' %}" class="btn btn-success">Import CSV</a>
        <a href="{% url 'crm:send-bulk-email' %}" class="btn btn-primary">Send Email</a>
    </div> -->

    <span>{{ filter.qs|length }} résultats</span>

    <div class="table-responsive">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th><input type="checkbox" id="select-all"></th>
                    <th>Entité</th>
                    <th>Prénom</th>
                    <th>Nom</th>
                    <th>Email</th>
                    <th>Ville</th>
                    <th>Statut</th>
                    <th>Actions</th>
                </tr>
            </thead>
            <tbody>
                {% for prospect in filter.qs %}
                <tr>
                    <td><input type="checkbox" name="selected_prospects" value="{{ prospect.id }}"></td>
                    <td>{{ prospect.entity_name }}</td>
                    <td>{{ prospect.first_name }}</td>
                    <td>{{ prospect.last_name }}</td>
                    <td><a href="mailto:{{ prospect.email }}">{{ prospect.email }}</a></td>
                    <td>{{ prospect.city }} ({{ prospect.zip_code }})</td>
                    <td>
                        {% for status in prospect.prospectstatus_set.all %}
                            <span class="badge bg-primary">{{ status.status.name }}</span>
                        {% endfor %}
                    </td>
                    <td>
                        <a href="{% url 'crm:edit-prospect' prospect.id %}">
                            <button class="btn btn-sm btn-secondary">Edit</button>
                        </a>

                        <a href="{% url 'crm:add-event-for-prospect' prospect.id %}">
                            <button class="btn btn-sm btn-secondary">+ Event</button>
                        </a>
                    </td>
                </tr>
                {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}

{% block extra_js %}
<script src="{% static 'crm/js/prospects.js' %}"></script>
{% endblock %}
