{% extends "base.html" %}
{% load i18n static %}

{% block title %}{% trans "Shopping Cart" %}{% endblock %}

{% block content %}
<div class="container py-5">
  <h1 class="fw-bold mb-4">{% trans "Your Shopping Cart" %}</h1>

  {% if cart_items %}
  <div class="row g-5">
    <div class="col-lg-8">
      <div class="table-responsive">
        <table class="table align-middle">
          <thead>
            <tr>
              <th scope="col">{% trans "Product" %}</th>
              <th scope="col">{% trans "Price" %}</th>
              <th scope="col">{% trans "Quantity" %}</th>
              <th scope="col">{% trans "Subtotal" %}</th>
              <th scope="col"></th>
            </tr>
          </thead>
          <tbody>
            {% for item in cart_items %}
            <tr>
              <td>
                <div class="d-flex align-items-center">
                  {% if item.product.image %}
                    <img src="{{ item.product.image.url }}" alt="{{ item.product.name }}" class="rounded me-3" style="width: 60px; height: 60px; object-fit: cover;">
                  {% endif %}
                  <div>
                    <h6 class="mb-0">{{ item.product.name }}</h6>
                    <small class="text-muted">{{ item.product.vendor.business_name }}</small>
                  </div>
                </div>
              </td>
              <td>{{ item.product.price }} ETB</td>
              <td>{{ item.quantity }}</td>
              <td>{{ item.subtotal }} ETB</td>
              <td>
                <a href="{% url 'cart_remove' item.product.id %}" class="text-danger">
                  <i class="bi bi-trash"></i> {% trans "Remove" %}
                </a>
              </td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
    <div class="col-lg-4">
      <div class="card border-0 shadow-sm p-4">
        <h4 class="fw-bold mb-4">{% trans "Order Summary" %}</h4>
        <div class="d-flex justify-content-between mb-2">
          <span>{% trans "Subtotal" %}</span>
          <span>{{ total }} ETB</span>
        </div>
        <div class="d-flex justify-content-between mb-4">
          <span>{% trans "Shipping" %}</span>
          <span class="text-success">{% trans "Free" %}</span>
        </div>
        <hr>
        <div class="d-flex justify-content-between mb-4">
          <span class="fw-bold">{% trans "Total" %}</span>
          <span class="fw-bold text-primary fs-4">{{ total }} ETB</span>
        </div>
        <a href="{% url 'checkout' %}" class="btn btn-primary btn-lg w-100">
          {% trans "Proceed to Checkout" %}
        </a>
      </div>
    </div>
  </div>
  {% else %}
  <div class="text-center py-5">
    <p class="lead text-muted mb-4">{% trans "Your cart is empty." %}</p>
    <a href="{% url 'product_list' %}" class="btn btn-primary">{% trans "Start Shopping" %}</a>
  </div>
  {% endif %}
</div>
{% endblock %}
