<div>
    {{-- Hero Section --}}
    <section class="relative h-[500px] flex items-center justify-center overflow-hidden">
        {{-- Background Image --}}
        <div class="absolute inset-0 z-0">
            <img src="https://images.pexels.com/photos/22589353/pexels-photo-22589353.jpeg" alt="Article Background"
                class="w-full h-full object-cover">
            <div class="absolute inset-0 bg-black/40"></div>
        </div>

        {{-- Content --}}
        <div class="relative z-10 container mx-auto px-6 text-center">
            <h1 class="text-4xl md:text-5xl lg:text-6xl font-bold text-white mb-6">{{ $pageTitle }}</h1>
            <p class="text-white/80 text-lg md:text-xl max-w-2xl mx-auto mb-10">
                {{ $pageDesc }}
            </p>

            {{-- Search Bar --}}
            <div class="max-w-xl mx-auto relative group">
                <input wire:model.live.debounce.500="search" type="search" placeholder="Cari produk..."
                    aria-label="Cari produk"
                    class="w-full py-4 pl-6 pr-14 rounded-full bg-white/10 backdrop-blur-md border border-white/20 text-white placeholder-white/60 focus:outline-none focus:ring-2 focus:ring-home-primary focus:bg-white/20 transition-all shadow-lg text-lg">
                <button
                    class="absolute right-2 top-2 bottom-2 w-10 h-10 bg-home-primary rounded-full flex items-center justify-center text-white hover:bg-white hover:text-home-primary transition-all duration-300">
                    <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                            d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"></path>
                    </svg>
                </button>
            </div>
        </div>
    </section>

    <main class="px-6 lg:px-32 xl:px-48 py-24 bg-white text-black font-sans">

        <div class="grid grid-cols-1 lg:grid-cols-4 gap-12 mb-24">

            <aside class="hidden lg:block lg:col-span-1 space-y-8">
                <div class="bg-white rounded-2xl border border-home-foreground/10 p-6 shadow-sm sticky top-32">
                    {{-- Product type filter --}}
                    <h3 class="font-bold text-home-primary mb-6 border-b border-home-foreground/10 pb-4">Jenis Produk
                    </h3>
                    <div class="space-y-4">
                        @foreach ([['value' => 'perfume', 'label' => 'Parfum'], ['value' => 'bottle', 'label' => 'Botol'], ['value' => 'arabian', 'label' => 'Arabian']] as $type)
                            <label class="flex items-center cursor-pointer group">
                                <input type="radio" name="productType" value="{{ $type['value'] }}"
                                    wire:model.live="productType"
                                    class="w-5 h-5 border-home-foreground/20 text-home-primary focus:ring-home-primary cursor-pointer accent-home-primary">
                                <span
                                    class="ml-3 text-home-foreground/70 group-hover:text-home-primary transition-colors text-sm font-medium {{ $productType === $type['value'] ? 'font-bold text-home-primary' : '' }}">{{ $type['label'] }}</span>
                            </label>
                        @endforeach
                    </div>

                    <div class="border-t border-home-foreground/10 my-8"></div>

                    @if ($productType === 'perfume')
                        <h3 class="font-bold text-home-primary mb-6 border-b border-home-foreground/10 pb-4">Kategori
                        </h3>
                        <div class="space-y-4">
                            @foreach ($availableCategories as $id => $name)
                                <label class="flex items-center cursor-pointer group">
                                    <input type="checkbox" value="{{ $name }}"
                                        wire:model.live="selectedCategories"
                                        class="w-5 h-5 rounded border-home-foreground/20 text-home-primary focus:ring-home-primary cursor-pointer accent-home-primary">
                                    <span
                                        class="ml-3 text-home-foreground/70 group-hover:text-home-primary transition-colors text-sm font-medium">{{ $name }}</span>
                                </label>
                            @endforeach
                        </div>

                        <div class="border-t border-home-foreground/10 my-8"></div>
                    @endif

                    <h3 class="font-bold text-home-primary mb-6 border-b border-home-foreground/10 pb-4">Harga</h3>
                    <div class="space-y-4">
                        @foreach (['< 100k', '100k - 500k', '500k - 1jt', '> 1jt'] as $price)
                            <label class="flex items-center cursor-pointer group">
                                <input type="radio" name="price" value="{{ $price }}"
                                    wire:model.live="priceRange"
                                    class="w-5 h-5 border-home-foreground/20 text-home-primary focus:ring-home-primary cursor-pointer accent-home-primary">
                                <span
                                    class="ml-3 text-home-foreground/70 group-hover:text-home-primary transition-colors text-sm font-medium">{{ $price }}</span>
                            </label>
                        @endforeach
                    </div>
                </div>
            </aside>

            <section class="lg:col-span-3">

                {{-- Toolbar (Sort Only) --}}
                <div class="flex justify-end mb-8">
                    <div class="relative min-w-[200px]">
                        <select wire:model.live="sort"
                            class="w-full appearance-none px-6 py-3 pr-10 rounded-xl border border-home-foreground/10 bg-white text-home-foreground font-medium focus:outline-none focus:ring-2 focus:ring-home-primary focus:border-transparent transition cursor-pointer shadow-sm">
                            <option value="latest">Urutkan: Terbaru</option>
                            <option value="price_low">Harga Terendah</option>
                            <option value="price_high">Harga Tertinggi</option>
                            <option value="popular">Terpopuler</option>
                        </select>
                        <svg class="absolute right-4 top-4 w-4 h-4 text-home-foreground/50 pointer-events-none"
                            fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7">
                            </path>
                        </svg>
                    </div>
                </div>

                @if ($products->isNotEmpty())
                    <div class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-8">
                        @foreach ($products as $product)
                            <article
                                class="group bg-white rounded-2xl border border-home-foreground/10 overflow-hidden hover:shadow-xl hover:shadow-home-primary/5 hover:border-home-primary/30 hover:-translate-y-1 transition-all duration-300 flex flex-col h-full relative">

                                @if (isset($product->badge) && $product->badge)
                                    <span
                                        class="absolute top-4 left-4 {{ $product->badge['class'] }} text-[10px] uppercase tracking-wider font-bold px-3 py-1 rounded-full z-10 shadow-md">
                                        {{ $product->badge['label'] }}
                                    </span>
                                @endif

                                <div class="relative h-72 overflow-hidden bg-home-primary/5">
                                    <img src="{{ $product['image'] }}" alt="{{ $product['name'] }}"
                                        class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500">

                                    <div
                                        class="absolute inset-0 bg-black/20 opacity-0 group-hover:opacity-100 transition-opacity duration-300 flex items-center justify-center gap-3">
                                        <a href="{{ route('product.show', $product->slug) }}" wire:navigate
                                            class="w-10 h-10 bg-white rounded-full flex items-center justify-center text-home-foreground hover:bg-home-primary hover:text-white transition-all shadow-lg transform hover:scale-110"
                                            title="Lihat Detail">
                                            <svg class="w-5 h-5" fill="none" stroke="currentColor"
                                                viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                                    d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                                    d="M2.458 12C3.732 7.943 7.523 5 12 5c4.478 0 8.268 2.943 9.542 7-1.274 4.057-5.064 7-9.542 7-4.477 0-8.268-2.943-9.542-7z">
                                                </path>
                                            </svg>
                                        </a>
                                        {{-- Not used yet --}}
                                        {{-- <button
                                            class="w-10 h-10 bg-white rounded-full flex items-center justify-center text-home-foreground hover:bg-home-primary hover:text-white transition-all shadow-lg transform hover:scale-110"
                                            title="Simpan ke Wishlist">
                                            <svg class="w-5 h-5" fill="none" stroke="currentColor"
                                                viewBox="0 0 24 24">
                                                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                                    d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z">
                                                </path>
                                            </svg>
                                        </button> --}}
                                    </div>
                                </div>

                                <div class="p-5 flex flex-col flex-grow">
                                    @if ($productType === 'perfume')
                                        <div class="flex flex-wrap gap-2 mb-2">
                                            @foreach ($product->categories->take(3) as $category)
                                                <span
                                                    class="text-xs font-bold text-home-primary bg-home-primary/10 px-3 py-1 rounded-full border border-home-primary/10 uppercase tracking-wider whitespace-nowrap">
                                                    {{ $category->name }}
                                                </span>
                                            @endforeach

                                            @if ($product->categories->count() > 3)
                                                <span
                                                    class="text-xs font-bold text-home-foreground/50 px-3 py-1 rounded-full border border-home-foreground/10 whitespace-nowrap">
                                                    +{{ $product->categories->count() - 3 }}
                                                </span>
                                            @endif

                                            {{-- Not used yet --}}
                                            {{-- <div class="flex items-center gap-1">
                                        <svg class="w-3 h-3 text-yellow-400" fill="currentColor" viewBox="0 0 20 20">
                                            <path
                                                d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.07 3.292a1 1 0 00.95.69h3.462c.969 0 1.371 1.24.588 1.81l-2.8 2.034a1 1 0 00-.364 1.118l1.07 3.292c.3.921-.755 1.688-1.54 1.118l-2.8-2.034a1 1 0 00-1.175 0l-2.8 2.034c-.784.57-1.838-.197-1.539-1.118l1.07-3.292a1 1 0 00-.364-1.118L2.98 8.72c-.783-.57-.38-1.81.588-1.81h3.461a1 1 0 00.951-.69l1.07-3.292z" />
                                        </svg>
                                        <span
                                            class="text-xs font-bold text-home-foreground">{{ $product['rating'] }}</span>
                                        <span
                                            class="text-xs text-home-foreground/40">({{ $product['reviews'] }})</span>
                                    </div> --}}
                                        </div>
                                    @endif

                                    <h3
                                        class="text-lg font-bold text-home-foreground group-hover:text-home-primary transition-colors my-4 line-clamp-1">
                                        <a
                                            href="{{ route('product.show', $product['slug']) }}">{{ $product['name'] }}</a>
                                    </h3>

                                    <div
                                        class="mt-auto pt-4 border-t border-home-foreground/5 flex items-center justify-between">
                                        <span class="text-xl font-bold text-home-primary">Rp
                                            {{ formatCurrencyNumber($product['sale_price']) }}</span>

                                        {{-- Not used yet --}}
                                        {{-- <button
                                        class="w-10 h-10 rounded-lg bg-home-foreground text-white flex items-center justify-center hover:bg-home-primary transition-colors shadow-md">
                                        <svg class="w-5 h-5" fill="none" stroke="currentColor"
                                            viewBox="0 0 24 24">
                                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                                d="M12 4v16m8-8H4"></path>
                                        </svg>
                                    </button> --}}
                                    </div>
                                </div>
                            </article>
                        @endforeach
                    </div>
                @else
                    @include('components.animations.lottie.not-found')
                @endif

                <div class="mt-16">
                    {{ $products->links('vendor.livewire.custom-pagination') }}
                </div>
            </section>
        </div>

        <section class="mt-24 pt-16 border-t border-home-foreground/10">
            <div class="flex items-center justify-between mb-12">
                <h2 class="text-2xl md:text-3xl font-bold text-home-primary">Mungkin Anda Suka</h2>
                <div class="flex gap-3">
                    <button id="slideLeft"
                        class="w-12 h-12 rounded-full border border-home-foreground/10 flex items-center justify-center text-home-foreground hover:bg-home-primary hover:text-white hover:border-home-primary transition-all shadow-sm">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                d="M15 19l-7-7 7-7"></path>
                        </svg>
                    </button>
                    <button id="slideRight"
                        class="w-12 h-12 rounded-full border border-home-foreground/10 flex items-center justify-center text-home-foreground hover:bg-home-primary hover:text-white hover:border-home-primary transition-all shadow-sm">
                        <svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7">
                            </path>
                        </svg>
                    </button>
                </div>
            </div>

            <div id="productSlider"
                class="flex gap-6 overflow-x-auto pb-12 snap-x snap-mandatory scroll-smooth hide-scrollbar"
                style="scrollbar-width: none; -ms-overflow-style: none;">
                @foreach ($recommendations as $rec)
                    <article
                        class="min-w-[280px] md:min-w-[300px] bg-white rounded-2xl border border-home-foreground/10 overflow-hidden hover:shadow-xl hover:border-home-primary/30 transition-all duration-300 snap-start group flex flex-col h-full">
                        <div class="h-60 overflow-hidden relative bg-home-primary/5">
                            <img src="{{ $rec['image'] }}" alt="{{ $rec['image'] }}"
                                class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-500">
                        </div>
                        <div class="p-5 flex flex-col flex-grow">
                            <div class="flex flex-wrap gap-2 mb-2">
                                @foreach (array_slice($rec['categories'], 0, 3) as $category)
                                    <span
                                        class="text-xs font-bold text-home-primary bg-home-primary/10 px-3 py-1 rounded-full border border-home-primary/10 uppercase tracking-wider whitespace-nowrap">
                                        {{ $category['name'] }}
                                    </span>
                                @endforeach

                                @if (count($rec['categories']) > 3)
                                    <span
                                        class="text-xs font-bold text-home-foreground/50 px-3 py-1 rounded-full border border-home-foreground/10 whitespace-nowrap">
                                        +{{ count($rec['categories']) - 3 }}
                                    </span>
                                @endif
                            </div>
                            <h3 class="text-lg font-bold text-home-foreground mb-1">
                                <a href="{{ route('product.show', $rec['slug']) }}">
                                    {{ $rec['name'] }}</a>
                            </h3>
                            <div class="mt-auto pt-4 flex items-center justify-between">
                                <span class="font-bold text-home-primary">Rp
                                    {{ formatCurrencyNumber($rec['sale_price']) }}</span>

                                {{-- Not used yet --}}
                                {{-- <button
                                    class="w-8 h-8 rounded bg-home-foreground/5 text-home-foreground hover:bg-home-primary hover:text-white flex items-center justify-center transition-colors">
                                    <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M12 4v16m8-8H4"></path>
                                    </svg>
                                </button> --}}
                            </div>
                        </div>
                    </article>
                @endforeach
            </div>
        </section>

    </main>
</div>

@assets
    <script src="https://unpkg.com/@lottiefiles/dotlottie-wc@0.8.5/dist/dotlottie-wc.js" type="module"></script>
@endassets
