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

{% block content %}
<!-- Hero Section -->
<section class="hero-section">
    <div class="container">
        <div class="row align-items-center">
            <div class="col-lg-6">
                <span class="badge bg-emerald mb-3 px-3 py-2 rounded-pill">Digitalisasi UMKM Desa</span>
                <h1 class="hero-title mb-4">Majukan Ekonomi Desa Pemagarsari</h1>
                <p class="lead text-muted mb-4">Temukan produk unggulan dari warga desa kami. Pesan langsung via WhatsApp tanpa ribet, dukung produk lokal hari ini.</p>
                
                <!-- Search Bar -->
                <form action="{% url 'home' %}" method="GET" class="mb-4">
                    <div class="search-box p-2 bg-white rounded-pill shadow-sm d-flex">
                        <input type="text" name="q" value="{{ query }}" class="form-control border-0 bg-transparent px-4 shadow-none" placeholder="Cari kerajinan, makanan, atau jasa...">
                        <button type="submit" class="btn btn-emerald rounded-pill px-4">
                            <i class="fa-solid fa-magnifying-glass me-2"></i>Cari
                        </button>
                    </div>
                </form>

                <div class="d-flex flex-wrap gap-3">
                    <a href="#produk" class="btn btn-outline-emerald rounded-pill px-4">Jelajahi Produk</a>
                    {% if query or selected_category %}
                    <a href="{% url 'home' %}" class="btn btn-link text-muted text-decoration-none">Reset Filter</a>
                    {% endif %}
                </div>
            </div>
            <div class="col-lg-6 d-none d-lg-block text-center">
                <div class="position-relative p-4">
                    <div class="bg-emerald rounded-circle position-absolute top-50 start-50 translate-middle opacity-10" style="width: 500px; height: 500px; filter: blur(60px);"></div>
                    <div class="position-relative z-1 shadow-lg rounded-4 overflow-hidden border border-white border-4 transform-hover transition-all">
                        <img src="https://images.unsplash.com/photo-1590632823277-285f21442df1?auto=format&fit=crop&q=80&w=800" alt="Pasar Tradisional Desa" class="img-fluid" style="max-height: 450px; width: 100%; object-fit: cover;">
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>

<!-- Categories -->
<section id="kategori" class="py-5">
    <div class="container">
        <div class="text-center mb-5">
            <h2 class="fw-bold">Kategori Populer</h2>
            <p class="text-muted">Cari produk berdasarkan kategori</p>
        </div>
        <div class="row g-4 justify-content-center">
            <div class="col-6 col-md-2">
                <a href="{% url 'home' %}" class="category-card {% if not selected_category %}active{% endif %}">
                    <div class="category-icon">
                        <i class="fa-solid fa-border-all"></i>
                    </div>
                    <h6 class="fw-bold mb-0 text-dark">Semua</h6>
                </a>
            </div>
            {% for category in categories %}
            <div class="col-6 col-md-2">
                <a href="?category={{ category.slug }}{% if query %}&q={{ query }}{% endif %}" class="category-card {% if selected_category == category.slug %}active{% endif %}">
                    <div class="category-icon">
                        <i class="fa-solid {{ category.icon }}"></i>
                    </div>
                    <h6 class="fw-bold mb-0 text-dark">{{ category.name }}</h6>
                </a>
            </div>
            {% endfor %}
        </div>
    </div>
</section>

<!-- Featured Products -->
<section id="produk" class="py-5 bg-light">
    <div class="container">
        <div class="text-center mb-5">
            <h2 class="fw-bold">Produk Terbaru</h2>
            <p class="text-muted">Produk unggulan dari para pengrajin dan pedagang desa</p>
        </div>
        <div class="row g-4">
            {% for product in featured_products %}
            <div class="col-12 col-sm-6 col-lg-3">
                <div class="product-card">
                    <div class="product-img-wrapper">
                        {% if product.image %}
                        <img src="{{ product.image.url }}" alt="{{ product.name }}" class="img-fluid w-100 h-100 object-fit-cover">
                        {% else %}
                        <i class="fa-solid fa-image"></i>
                        {% endif %}
                    </div>
                    <div class="p-4">
                        <div class="d-flex justify-content-between align-items-center mb-2">
                            <span class="shop-badge">{{ product.shop.name }}</span>
                            <small class="text-muted">{{ product.category.name }}</small>
                        </div>
                        <h5 class="fw-bold mb-3">
                            <a href="{% url 'product_detail' product.slug %}" class="text-decoration-none text-dark">{{ product.name }}</a>
                        </h5>
                        <div class="d-flex justify-content-between align-items-center">
                            <span class="product-price">Rp {{ product.price|floatformat:0 }}</span>
                            <a href="{{ product.whatsapp_link }}" target="_blank" class="btn btn-whatsapp btn-sm px-3">
                                <i class="fa-brands fa-whatsapp me-2"></i>Pesan
                            </a>
                        </div>
                    </div>
                </div>
            </div>
            {% empty %}
            <div class="col-12 text-center py-5">
                <div class="bg-white p-5 rounded-4 shadow-sm">
                    <i class="fa-solid fa-box-open fa-3x text-muted mb-3"></i>
                    <p class="text-muted">Belum ada produk untuk ditampilkan.</p>
                    <a href="/admin/core/product/add/" class="btn btn-emerald mt-3">Tambah Produk Pertama</a>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>
</section>

<!-- Call to Action -->
<section class="py-5">
    <div class="container">
        <div class="p-5 rounded-4 text-white text-center position-relative overflow-hidden shadow-lg" style="background: linear-gradient(135deg, rgba(6, 78, 59, 0.9) 0%, rgba(16, 185, 129, 0.9) 100%), url('https://images.unsplash.com/photo-1544333346-64e4fe18204b?auto=format&fit=crop&q=80&w=1200'); background-size: cover; background-position: center;">
            <div class="position-relative z-1">
                <h2 class="fw-bold mb-3">Punya Usaha di Desa Pemagarsari?</h2>
                <p class="mb-4 opacity-75">Daftarkan toko Anda dan mulai jualan online hari ini. Mudah, gratis, dan langsung ke WhatsApp!</p>
                <div class="d-flex justify-content-center gap-3">
                    <a href="{% if user.is_authenticated %}{% url 'dashboard' %}{% else %}{% url 'login' %}{% endif %}" class="btn btn-emerald btn-lg px-5 rounded-pill shadow-lg">Mulai Jualan Sekarang</a>
                </div>
            </div>
        </div>
    </div>
</section>
{% endblock %}
