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

{% block title %}{{ vendor.name }} - UMKM Desa Pemagarsari{% endblock %}

{% block content %}
<!-- Vendor Header -->
<section class="py-4 py-md-5 bg-white border-bottom shadow-sm">
    <div class="container py-2 text-center px-4 px-md-0">
        <div class="mb-4">
            {% if vendor.logo %}
                <img src="{{ vendor.logo.url }}" class="rounded-circle shadow-sm mb-3 vendor-logo-img" >
            {% else %}
                <div class="rounded-circle bg-primary text-white d-flex align-items-center justify-content-center shadow-sm mb-3 mx-auto vendor-logo-img" >
                    <i class="fas fa-store fa-3x"></i>
                </div>
            {% endif %}
        </div>
        <h1 class="h2 mb-2">{{ vendor.name }}</h1>
        <p class="lead text-muted max-width-700 mx-auto small mb-4">{{ vendor.description|default:"Toko terpercaya di Desa Pemagarsari." }}</p>
        
        <div class="d-flex flex-column flex-sm-row justify-content-center gap-2 gap-md-3 mt-4">
            <a href="https://wa.me/{{ vendor.whatsapp_number }}" target="_blank" class="btn btn-outline-success px-4 rounded-pill shadow-sm">
                <i class="fab fa-whatsapp me-2"></i> Chat Penjual
            </a>
            <div class="btn btn-outline-secondary px-4 rounded-pill shadow-sm">
                <i class="fas fa-map-marker-alt me-2"></i> {{ vendor.address|default:"Desa Pemagarsari" }}
            </div>
        </div>
    </div>
</section>

<!-- Vendor Products -->
<section class="py-4 py-md-5 bg-light">
    <div class="container py-2">
        <div class="d-flex flex-column flex-sm-row justify-content-between align-items-center align-items-sm-end mb-4 mb-md-5 text-center text-sm-start gap-2">
            <div>
                <h2 class="h3 mb-1">Produk Dari Toko Ini</h2>
                <p class="text-muted mb-0">Katalog lengkap {{ vendor.name }}</p>
            </div>
            <span class="badge bg-white text-primary border shadow-sm px-3 py-2 rounded-pill">{{ products|length }} Produk</span>
        </div>
        
        <div class="row g-3 g-md-4">
            {% if products %}
                {% for product in products %}
                <div class="col-6 col-md-3">
                    <div class="card h-100 shadow-sm border-0">
                        <div class="position-relative">
                            {% if product.image %}
                                <img src="{{ product.image.url }}" class="card-img-top product-img-vendor" alt="{{ product.name }}" >
                            {% else %}
                                <div class="bg-secondary-subtle d-flex align-items-center justify-content-center product-img-vendor" >
                                    <i class="fas fa-image fa-2x text-muted opacity-50"></i>
                                </div>
                            {% endif %}
                        </div>
                        <div class="card-body p-3 p-md-4 d-flex flex-column">
                            <h5 class="card-title mb-1 small fw-bold">
                                <a href="{% url 'product_detail' product.slug %}" class="text-decoration-none text-dark">{{ product.name }}</a>
                            </h5>
                            <p class="product-price mb-3">Rp {{ product.price|floatformat:0 }}</p>
                            <div class="d-grid mt-auto">
                                <a href="{{ product.get_whatsapp_url }}" target="_blank" class="btn btn-sm wa-btn shadow-sm py-2 px-1">
                                    <i class="fab fa-whatsapp me-1"></i> Beli Sekarang
                                </a>
                            </div>
                        </div>
                    </div>
                </div>
                {% endfor %}
            {% else %}
                <div class="col-12 text-center py-5">
                    <i class="fas fa-box-open fa-4x text-muted mb-4 opacity-50"></i>
                    <h3 class="text-muted">Maaf, toko ini belum memiliki produk.</h3>
                    <p class="text-muted">Silakan kembali lagi nanti atau lihat produk dari toko lain.</p>
                    <a href="{% url 'product_list' %}" class="btn btn-primary mt-3 px-4 rounded-pill">Jelajahi Produk Lain</a>
                </div>
            {% endif %}
        </div>
    </div>
</section>
{% endblock %}