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

{% block breadcrumbs %}
<div class="breadcrumb-container">
    <div class="container">
        <nav aria-label="breadcrumb">
            <ol class="breadcrumb mb-0">
                <li class="breadcrumb-item"><a href="/"><i class="fa-solid fa-house me-1"></i> {% trans "Home" %}</a></li>
                <li class="breadcrumb-item"><a href="{% url 'dashboard' %}">{% trans "Dashboard" %}</a></li>
                <li class="breadcrumb-item active" aria-current="page">{% trans "Marketplace" %}</li>
            </ol>
        </nav>
    </div>
</div>
{% endblock %}

{% block content %}
<div class="container py-4">
    <div class="mb-4">
        <a href="{% url 'dashboard' %}" class="btn btn-outline-secondary btn-sm">
            <i class="fa-solid fa-arrow-left me-1"></i> {% trans "Back to Dashboard" %}
        </a>
    </div>

    <h2 class="mb-4">{% trans "Truck Marketplace" %}</h2>
    <p class="text-muted mb-4">{% trans "Browse available trucks and send your shipping offers directly to truck owners." %}</p>
    
    <div class="row">
        {% for truck in trucks %}
        <div class="col-md-6 col-lg-4 mb-4">
            <div class="card shadow-sm h-100 border-0 overflow-hidden">
                {% if truck.truck_picture %}
                <img src="{{ truck.truck_picture.url }}" class="card-img-top" alt="{{ truck.display_truck_type }}" style="height: 200px; object-fit: cover;">
                {% else %}
                <div class="bg-light d-flex align-items-center justify-content-center" style="height: 200px;">
                    <i class="fa-solid fa-truck fa-4x text-muted opacity-25"></i>
                </div>
                {% endif %}
                <div class="card-body">
                    <div class="d-flex justify-content-between mb-2">
                        <span class="badge bg-success">{% trans "Available" %}</span>
                        <small class="text-muted">{% trans "Plate" %}: {{ truck.plate_no }}</small>
                    </div>
                    <h5 class="card-title">{{ truck.display_truck_type }} - {{ truck.display_model }}</h5>
                    <div class="mb-3">
                        <span class="badge bg-light text-dark">{% trans "Year" %}: {{ truck.year }}</span>
                        <span class="badge bg-light text-dark">{% trans "Capacity" %}: {{ truck.display_load_capacity }}</span>
                    </div>
                    <p class="card-text">
                        <small class="text-muted d-block">{% trans "Owner" %}: {{ truck.owner.username }}</small>
                    </p>
                    <a href="{% url 'place_bid' truck.id %}" class="btn btn-primary w-100">
                        <i class="fa-solid fa-paper-plane me-2"></i>{% trans "Send Shipping Offer" %}
                    </a>
                </div>
            </div>
        </div>
        {% empty %}
        <div class="col-12 text-center py-5">
            <div class="py-5">
                <i class="fa-solid fa-truck-slash fa-4x text-muted mb-3"></i>
                <p class="lead text-muted">{% trans "No approved trucks are currently available." %}</p>
            </div>
        </div>
        {% endfor %}
    </div>
</div>
{% endblock %}