{% extends 'base.html' %}

{% block content %}
<div class="container mt-5">
    <h1>Opportunities</h1>
    <a href="{% url 'opportunities:opportunity_create' %}" class="btn btn-primary mb-3">Create Opportunity</a>
    <table class="table">
        <thead>
            <tr>
                <th>Name</th>
                <th>Lead</th>
                <th>Stage</th>
                <th>Value</th>
                <th>Close Date</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            {% for opportunity in opportunities %}
            <tr>
                <td><a href="{% url 'opportunities:opportunity_detail' opportunity.pk %}">{{ opportunity.name }}</a></td>
                <td>{{ opportunity.lead.customer.name }}</td>
                <td>{{ opportunity.get_stage_display }}</td>
                <td>${{ opportunity.value|default:0 }}</td>
                <td>{{ opportunity.close_date|date:"Y-m-d" }}</td>
                <td>
                    <a href="{% url 'opportunities:opportunity_update' opportunity.pk %}" class="btn btn-sm btn-warning">Edit</a>
                    <a href="{% url 'opportunities:opportunity_delete' opportunity.pk %}" class="btn btn-sm btn-danger">Delete</a>
                </td>
            </tr>
            {% empty %}
            <tr>
                <td colspan="6">No opportunities found.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}
