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

{% block content %}
<!-- Main Banner -->
<div class="container-fluid px-0 mb-4">
    <div class="banner-wrapper">
        <img src="{% static 'images/banner.png' %}" alt="Banner Desa Pemagarsari" class="banner-img">
        <div class="position-absolute top-0 start-0 w-100 h-100 d-flex align-items-center justify-content-center bg-dark bg-opacity-25">
            <h2 class="text-white fw-bold d-md-none">Desa Pemagarsari</h2>
        </div>
    </div>
</div>

<!-- Hero Section -->
<section class="hero-section">
    <div class="container">
        <div class="row align-items-center g-4">
            <div class="col-lg-6 order-2 order-lg-1">
                <div class="d-inline-block badge bg-orange mb-3 px-3 py-2 rounded-pill">Digitalisasi UMKM Desa</div>
                <h1 class="hero-title mb-4">Majukan Ekonomi Desa Pemagarsari</h1>
                <p class="lead text-muted mb-4 text-center text-lg-start">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|default:'' }}" class="form-control border-0 bg-transparent px-3 px-md-4 shadow-none" placeholder="Cari produk...">
                        <button type="submit" class="btn btn-orange rounded-pill px-3 px-md-4">
                            <i class="fa-solid fa-magnifying-glass"></i><span class="d-none d-md-inline ms-2">Cari</span>
                        </button>
                    </div>
                </form>

                <div class="d-flex flex-wrap gap-3 justify-content-center justify-content-lg-start">
                    <a href="#produk" class="btn btn-orange 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 order-1 order-lg-2">
                <div class="position-relative p-2 p-md-4">
                    <div class="bg-orange rounded-circle position-absolute top-50 start-50 translate-middle opacity-10 d-none d-md-block" style="width: 100%; height: 100%; 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 mx-auto" style="max-width: 500px; aspect-ratio: 4/3;">
                        <img src="https://images.unsplash.com/photo-1488459716781-31db52582fe9?auto=format&fit=crop&q=90&w=800" alt="Pasar Tradisional Desa" class="w-100 h-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-orange 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(30, 58, 138, 0.85) 0%, rgba(249, 115, 22, 0.75) 100%), url('https://images.unsplash.com/photo-1516253593875-bd7ba052fbc5?auto=format&fit=crop&q=90&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-orange btn-lg px-5 rounded-pill shadow-lg">Mulai Jualan Sekarang</a>
                </div>
            </div>
        </div>
    </div>
</section>
{% endblock %}
