{% extends "base.html" %}

{% block title %}Shopping Cart | Ethio-gebeya{% endblock %}

{% block content %}
<main class="container py-4">
    <h1 class="mb-4">Shopping Cart</h1>
    
    {% if items %}
    <table class="table">
        <thead>
            <tr>
                <th>Product</th>
                <th>Quantity</th>
                <th>Price</th>
                <th>Subtotal</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            {% for item in items %}
            <tr>
                <td>{{ item.product.name }}</td>
                <td>{{ item.quantity }}</td>
                <td>{{ item.product.price }} ETB</td>
                <td>{{ item.subtotal }} ETB</td>
                <td><a href="{% url 'remove_from_cart' item.product.pk %}" class="btn btn-danger btn-sm">Remove</a></td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
    <div class="mt-3">
        <h4>Total: {{ total_price }} ETB</h4>
        <form method="post" action="{% url 'checkout' %}">
            {% csrf_token %}
            <button type="submit" class="btn btn-primary">Proceed to Checkout</button>
        </form>
    </div>
    {% else %}
    <p>Your cart is empty.</p>
    {% endif %}
    
    <div class="mt-4">
        <a href="{% url 'home' %}" class="btn btn-secondary">Continue Shopping</a>
    </div>
</main>
{% endblock %}