{% extends 'base.html' %}
{% load static %}

{% block content %}
<div class="container mt-4">
    <div class="d-flex justify-content-between align-items-center mb-4">
        <h1 class="display-4">Vendas</h1>
        <a href="{% url 'sale_create' %}" class="btn btn-primary">Nova Venda</a>
    </div>
    
    <p class="lead">Gerencie suas vendas.</p>

    <table class="table table-striped">
        <thead>
            <tr>
                <th>ID</th>
                <th>Cliente</th>
                <th>Vendedor</th>
                <th>Valor Total</th>
                <th>Comissão</th>
                <th>Data</th>
                <th>Ações</th>
            </tr>
        </thead>
        <tbody>
            {% for sale in sales %}
            <tr>
                <td>#{{ sale.id }}</td>
                <td>{{ sale.customer.name }}</td>
                <td>{{ sale.seller.name|default:"N/A" }}</td>
                <td>R$ {{ sale.total_amount|floatformat:2 }}</td>
                <td>R$ {{ sale.commission_amount|floatformat:2 }}</td>
                <td>{{ sale.sale_date|date:"d/m/Y" }}</td>
                <td>

                    <a href="{% url 'sale_update' sale.id %}" class="btn btn-sm btn-warning">Editar</a>
                    <a href="{% url 'sale_delete' sale.id %}" class="btn btn-sm btn-danger">Excluir</a>
                </td>
            </tr>
            {% empty %}
            <tr>
                <td colspan="7" class="text-center">Nenhuma venda cadastrada.</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endblock %}

