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

{% block title %}{% trans "Shopping Cart" %} | Jimma Market{% endblock %}

{% block content %}
<section class="py-5 bg-light min-vh-100">
  <div class="container">
    <h2 class="fw-bold mb-5">{% trans "Your Shopping Cart" %} 🛒</h2>

    {% if cart_items %}
    <div class="row g-5">
      <div class="col-lg-8">
        <div class="card border-0 shadow-sm rounded-4 overflow-hidden">
          <div class="table-responsive">
            <table class="table table-borderless align-middle mb-0">
              <thead class="bg-white border-bottom">
                <tr>
                  <th class="px-4 py-3 text-secondary small fw-bold">{% trans "Product" %}</th>
                  <th class="py-3 text-secondary small fw-bold">{% trans "Quantity" %}</th>
                  <th class="py-3 text-secondary small fw-bold">{% trans "Subtotal" %}</th>
                  <th class="py-3"></th>
                </tr>
              </thead>
              <tbody class="bg-white">
                {% for item in cart_items %}
                <tr class="border-bottom-light">
                  <td class="px-4 py-4">
                    <div class="d-flex align-items-center">
                      <div class="bg-light rounded-3 p-1 me-3" style="width: 70px; height: 70px;">
                        {% if item.product.image %}
                          <img src="{{ item.product.image.url }}" class="img-fluid rounded-2 h-100 w-100" style="object-fit: cover;">
                        {% else %}
                          <div class="h-100 w-100 d-flex align-items-center justify-content-center">
                            <i class="bi bi-image text-secondary"></i>
                          </div>
                        {% endif %}
                      </div>
                      <div>
                        <h6 class="fw-bold mb-1">
                          <a href="{% url 'product_detail' item.product.slug %}" class="text-decoration-none text-dark">{{ item.product.name }}</a>
                        </h6>
                        <small class="text-secondary">{{ item.product.category.name }}</small>
                      </div>
                    </div>
                  </td>
                  <td class="py-4">
                    <div class="d-flex align-items-center bg-light rounded-pill px-3 py-1" style="width: fit-content;">
                      <span class="fw-bold">{{ item.quantity }}</span>
                    </div>
                  </td>
                  <td class="py-4">
                    <span class="fw-bold text-primary">{{ item.subtotal }} ETB</span>
                  </td>
                  <td class="py-4 pe-4 text-end">
                    <a href="{% url 'cart_remove' item.product.id %}" class="btn btn-link text-danger p-0">
                      <i class="bi bi-trash fs-5"></i>
                    </a>
                  </td>
                </tr>
                {% endfor %}
              </tbody>
            </table>
          </div>
        </div>
        
        <div class="mt-4">
          <a href="{% url 'product_list' %}" class="btn btn-link text-secondary text-decoration-none">
            <i class="bi bi-arrow-left me-2"></i> {% trans "Continue Shopping" %}
          </a>
        </div>
      </div>

      <div class="col-lg-4">
        <div class="card border-0 shadow-sm p-4 rounded-4">
          <h5 class="fw-bold mb-4">{% trans "Cart Total" %}</h5>
          <div class="d-flex justify-content-between mb-3">
            <span class="text-secondary">{% trans "Subtotal" %}</span>
            <span class="fw-bold">{{ total }} ETB</span>
          </div>
          <div class="d-flex justify-content-between mb-4">
            <span class="text-secondary">{% trans "Delivery" %}</span>
            <span class="text-success small fw-bold">{% trans "Calculated at checkout" %}</span>
          </div>
          <hr class="my-4 border-light">
          <div class="d-flex justify-content-between mb-5">
            <span class="h5 fw-bold mb-0">{% trans "Total" %}</span>
            <span class="h5 fw-bold mb-0 text-primary">{{ total }} ETB</span>
          </div>
          <a href="{% url 'checkout' %}" class="btn btn-primary btn-lg w-100 rounded-pill py-3 mb-3">
            {% trans "Proceed to Checkout" %}
          </a>
          <p class="small text-secondary text-center mb-0">
            {% trans "Secure & Easy Guest Checkout" %}
          </p>
        </div>
      </div>
    </div>
    {% else %}
    <div class="text-center py-5 bg-white rounded-5 shadow-sm">
      <div class="bg-light rounded-circle d-flex align-items-center justify-content-center mx-auto mb-4" style="width: 120px; height: 120px;">
        <i class="bi bi-cart-x display-1 text-secondary opacity-50"></i>
      </div>
      <h3 class="fw-bold">{% trans "Your cart is empty" %}</h3>
      <p class="text-secondary mb-5">{% trans "Looks like you haven't added anything to your cart yet." %}</p>
      <a href="{% url 'product_list' %}" class="btn btn-primary btn-lg rounded-pill px-5">{% trans "Start Shopping" %}</a>
    </div>
    {% endif %}
  </div>
</section>
{% endblock %}