<div>
    <div class="flex flex-col min-h-screen bg-white font-sans">

        {{-- 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.unsplash.com/photo-1761095870661-c4ae15cac605?q=80&w=880&auto=format&fit=crop&ixlib=rb-4.1.0&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D"
                    alt="Outlet Background" class="w-full h-full object-cover">
                <div class="absolute inset-0 bg-black/50"></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">Temukan Outlet Terdekat</h1>
                <p class="text-white/80 text-lg md:text-xl max-w-2xl mx-auto mb-10">
                    Rasakan pengalaman langsung kemewahan aroma kami. Kunjungi outlet kami untuk konsultasi personal.
                </p>

                {{-- Search Bar --}}
                <div class="max-w-xl mx-auto relative group">
                    <input type="text" wire:model.live="search" placeholder="Masukkan kota atau nama area..."
                        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="flex-grow px-6 lg:px-32 xl:px-48 py-24">

            <section class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-8 mb-24">
                @foreach ($outlets as $outlet)
                    <article wire:click="showDetail({{ $outlet['id'] }})"
                        class="group bg-white rounded-3xl border border-home-foreground/10 overflow-hidden hover:shadow-2xl hover:shadow-home-primary/10 hover:-translate-y-2 transition-all duration-500 flex flex-col h-full cursor-pointer">

                        <div class="relative h-64 overflow-hidden">
                            <div
                                class="absolute inset-0 bg-home-primary/10 mix-blend-multiply opacity-0 group-hover:opacity-100 transition-opacity duration-500 z-10">
                            </div>
                            <img src="{{ $outlet['image'] ?: 'https://placehold.co/800x600/png?text=' . urlencode($outlet['name']) }}"
                                alt="{{ $outlet['name'] }}"
                                class="w-full h-full object-cover transform group-hover:scale-110 transition-transform duration-700">

                            <div class="absolute top-4 left-4 z-20">
                                <span
                                    class="px-3 py-1 rounded-full text-[10px] font-bold uppercase tracking-wide backdrop-blur-md bg-white/90 shadow-sm
                                text-{{ $outlet['status_color'] }}-700">
                                    {{ $outlet['status_label'] }}
                                </span>
                            </div>
                        </div>

                        <div class="p-8 flex flex-col flex-grow">
                            <div class="mb-4">
                                <h3
                                    class="text-xl font-bold text-home-foreground mb-2 group-hover:text-home-primary transition-colors">
                                    {{ $outlet['name'] }}</h3>
                                <p class="text-sm text-home-foreground/60 leading-relaxed">{{ $outlet['address'] }}</p>
                            </div>

                            <div class="flex flex-wrap gap-2 mb-6">
                                @foreach ($outlet['facilities'] as $facility)
                                    <span
                                        class="text-[10px] px-2 py-1 border border-home-foreground/10 rounded text-home-foreground/50">
                                        {{ $facility['name'] }}
                                    </span>
                                @endforeach
                            </div>

                            <div class="mt-auto flex gap-3" x-on:click.stop>
                                @if ($outlet['maps_url'])
                                    <a href="{{ $outlet['maps_url'] }}" target="_blank"
                                        class="flex-1 py-3 rounded-xl bg-home-primary text-white text-sm font-bold hover:bg-home-secondary hover:text-home-primary transition-colors shadow-lg shadow-home-primary/20 flex items-center justify-center">
                                        Petunjuk Arah
                                    </a>
                                @endif
                                {{-- Share Menu --}}
                                <div class="relative" x-data="{ open: false }">
                                    <button @click="open = !open" @click.outside="open = false"
                                        class="w-12 h-12 rounded-xl border border-home-foreground/10 flex items-center justify-center text-home-foreground hover:border-home-primary hover:text-home-primary transition-all">
                                        <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="M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.316m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z">
                                            </path>
                                        </svg>
                                    </button>

                                    {{-- Dropdown Menu --}}
                                    <div x-show="open" x-transition:enter="transition ease-out duration-200"
                                        x-transition:enter-start="opacity-0 scale-95 translate-y-2"
                                        x-transition:enter-end="opacity-100 scale-100 translate-y-0"
                                        x-transition:leave="transition ease-in duration-150"
                                        x-transition:leave-start="opacity-100 scale-100 translate-y-0"
                                        x-transition:leave-end="opacity-0 scale-95 translate-y-2"
                                        class="absolute bottom-full mb-3 w-48 bg-white rounded-2xl shadow-xl border border-home-foreground/5 py-2 z-30 {{ $outlet['maps_url'] ? 'right-0' : 'left-0' }}"
                                        style="display: none;">

                                        <div
                                            class="px-4 py-2 text-[10px] font-bold text-home-foreground/40 uppercase tracking-widest border-b border-home-foreground/5 mb-1">
                                            Bagikan Ke
                                        </div>

                                        {{-- WhatsApp --}}
                                        <a href="https://wa.me/?text={{ urlencode('Cek ' . $outlet['name'] . ' di Yadi Parfum: ' . ($outlet['maps_url'] ?: url()->current())) }}"
                                            target="_blank"
                                            class="flex items-center gap-3 px-4 py-2 text-sm text-home-foreground hover:bg-home-primary/5 hover:text-home-primary transition-colors">
                                            <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
                                                <path
                                                    d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L0 24l6.335-1.662c1.72.94 3.659 1.437 5.634 1.437h.005c6.515 0 11.825-5.309 11.828-11.825a11.823 11.823 0 00-3.414-8.369" />
                                            </svg>
                                            WhatsApp
                                        </a>

                                        {{-- Facebook --}}
                                        <a href="https://www.facebook.com/sharer/sharer.php?u={{ urlencode($outlet['maps_url'] ?: url()->current()) }}"
                                            target="_blank"
                                            class="flex items-center gap-3 px-4 py-2 text-sm text-home-foreground hover:bg-home-primary/5 hover:text-home-primary transition-colors">
                                            <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
                                                <path
                                                    d="M24 12.073c0-6.627-5.373-12-12-12s-12 5.373-12 12c0 5.99 4.388 10.954 10.125 11.854v-8.385H7.078v-3.47h3.047V9.43c0-3.007 1.792-4.669 4.533-4.669 1.312 0 2.686.235 2.686.235v2.953H15.83c-1.491 0-1.956.925-1.956 1.874v2.25h3.328l-.532 3.47h-2.796v8.385C19.612 23.027 24 18.062 24 12.073z" />
                                            </svg>
                                            Facebook
                                        </a>

                                        {{-- X (Twitter) --}}
                                        <a href="https://twitter.com/intent/tweet?url={{ urlencode($outlet['maps_url'] ?: url()->current()) }}&text={{ urlencode('Cek outlet ' . $outlet['name'] . ' di Pangestu Yadi Parfum') }}"
                                            target="_blank"
                                            class="flex items-center gap-3 px-4 py-2 text-sm text-home-foreground hover:bg-home-primary/5 hover:text-home-primary transition-colors">
                                            <svg class="w-4 h-4" fill="currentColor" viewBox="0 0 24 24">
                                                <path
                                                    d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z" />
                                            </svg>
                                            X (Twitter)
                                        </a>

                                        {{-- Copy Link --}}
                                        <button
                                            @click="navigator.clipboard.writeText('{{ $outlet['maps_url'] ?: url()->current() }}'); $dispatch('notify', { message: 'Link berhasil disalin!', type: 'success' }); open = false"
                                            class="w-full flex items-center gap-3 px-4 py-2 text-sm text-home-foreground hover:bg-home-primary/5 hover:text-home-primary transition-colors text-left">
                                            <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="M8 5H6a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2v-1M8 5a2 2 0 002 2h2a2 2 0 002-2M8 5a2 2 0 012-2h2a2 2 0 012 2m0 0h2a2 2 0 012 2v3m2 4H10m0 0l3-3m-3 3l3 3">
                                                </path>
                                            </svg>
                                            Salin Tautan
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </article>
                @endforeach
            </section>

            <section class="relative rounded-3xl overflow-hidden shadow-2xl border border-home-foreground/10 group">
                <div
                    class="absolute inset-0 bg-home-foreground/5 z-10 pointer-events-none group-hover:bg-transparent transition-colors duration-500">
                </div>

                <iframe
                    src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d8506.860993234519!2d107.43951033371029!3d-6.543855086323806!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x2e690f57aa3eaf5b%3A0x2bbc334edbb98b17!2sYadi%20Parfum!5e1!3m2!1sen!2sid!4v1766221140539!5m2!1sen!2sid"
                    width="100%" height="450" style="border:0;" allowfullscreen="" loading="lazy"
                    referrerpolicy="no-referrer-when-downgrade"
                    style="border:0; filter: grayscale(100%) contrast(1.2);" allowfullscreen="" loading="lazy"
                    class="hover:filter-none transition-all duration-700">
                </iframe>
            </section>

        </main>
    </div>

    {{-- Detail Modal --}}
    @if ($selectedOutlet)
        <div class="fixed inset-0 z-[100] flex items-center justify-center p-4 sm:p-6 md:p-10" x-data
            x-on:keydown.escape.window="$wire.closeModal()">
            <!-- Backdrop -->
            <div class="absolute inset-0 bg-black/60 backdrop-blur-sm" wire:click="closeModal"
                x-transition:enter="transition ease-out duration-300" x-transition:enter-start="opacity-0"
                x-transition:enter-end="opacity-100" x-transition:leave="transition ease-in duration-200"
                x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0"></div>

            <!-- Modal Content -->
            <div class="relative bg-white w-full max-w-5xl max-h-full overflow-y-auto rounded-3xl shadow-2xl flex flex-col md:flex-row animate-in fade-in zoom-in duration-300"
                x-transition:enter="transition ease-out duration-300" x-transition:enter-start="opacity-0 scale-95"
                x-transition:enter-end="opacity-100 scale-100" x-transition:leave="transition ease-in duration-200"
                x-transition:leave-start="opacity-100 scale-100" x-transition:leave-end="opacity-0 scale-95">

                <!-- Close Button -->
                <button wire:click="closeModal"
                    class="absolute top-4 right-4 md:top-6 md:right-6 z-[60] w-10 h-10 rounded-full bg-white shadow-xl border border-home-foreground/5 text-home-foreground hover:text-home-primary hover:scale-110 transition-all flex items-center justify-center group"
                    title="Tutup">
                    <svg class="w-5 h-5 transition-transform group-hover:rotate-90 duration-300" fill="none"
                        stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                            d="M6 18L18 6M6 6l12 12">
                        </path>
                    </svg>
                </button>

                <!-- Left: Image Section (Gallery) -->
                @php
                    $allImages = collect();
                    if ($selectedOutlet->hasMedia('featured_image')) {
                        $allImages->push($selectedOutlet->getFirstMediaUrl('featured_image'));
                    }
                    if ($selectedOutlet->hasMedia('images')) {
                        foreach ($selectedOutlet->getMedia('images') as $media) {
                            $allImages->push($media->getUrl());
                        }
                    }
                    if ($allImages->isEmpty()) {
                        $allImages->push('https://placehold.co/800x600/png?text=' . urlencode($selectedOutlet->name));
                    }
                @endphp
                <div class="md:w-1/2 flex flex-col bg-gray-50" x-data="{
                    activeImage: '{{ $allImages->first() }}',
                    images: {{ $allImages->toJson() }}
                }">
                    <!-- Main Image Display -->
                    <div class="relative flex-grow h-[300px] md:h-auto overflow-hidden">
                        <template x-for="(img, index) in images" :key="index">
                            <img :src="img" x-show="activeImage === img"
                                x-transition:enter="transition ease-out duration-300"
                                x-transition:enter-start="opacity-0 scale-105"
                                x-transition:enter-end="opacity-100 scale-100"
                                class="absolute inset-0 w-full h-full object-cover"
                                alt="{{ $selectedOutlet->name }}">
                        </template>

                        <div
                            class="absolute inset-0 bg-gradient-to-t from-black/60 via-transparent to-transparent md:hidden">
                        </div>
                        <div class="absolute bottom-6 left-6 text-white md:hidden">
                            <h2 class="text-3xl font-bold">{{ $selectedOutlet->name }}</h2>
                        </div>
                    </div>

                    <!-- Thumbnails -->
                    @if ($allImages->count() > 1)
                        <div class="p-4 bg-white border-t border-gray-100">
                            <div class="flex gap-2 overflow-x-auto pb-2 scrollbar-none">
                                <template x-for="(img, index) in images" :key="index">
                                    <button @click="activeImage = img"
                                        class="relative w-20 h-20 rounded-xl overflow-hidden shrink-0 transition-all duration-300"
                                        :class="activeImage === img ? 'ring-2 ring-home-primary ring-offset-2 scale-95' :
                                            'opacity-60 hover:opacity-100'">
                                        <img :src="img" class="w-full h-full object-cover">
                                    </button>
                                </template>
                            </div>
                        </div>
                    @endif
                </div>

                <!-- Right: Details Section -->
                <div class="md:w-1/2 p-8 md:p-12">
                    <div class="hidden md:block mb-8">
                        <span class="text-home-primary font-bold tracking-widest text-xs uppercase mb-2 block">Detail
                            Outlet</span>
                        <h2 class="text-4xl font-bold text-home-foreground">{{ $selectedOutlet->name }}</h2>
                    </div>

                    <div class="space-y-8">
                        <!-- Status & Address -->
                        <div>
                            <div class="flex items-center gap-3 mb-4">
                                <span
                                    class="px-3 py-1 rounded-full text-[10px] font-bold uppercase tracking-wide
                                    {{ $selectedOutlet->status === \App\Enums\OutletStatus::OPERATIONAL ? 'bg-green-100 text-green-700' : 'bg-red-100 text-red-700' }}">
                                    {{ $selectedOutlet->status->label() }}
                                </span>
                            </div>
                            <div class="flex items-start gap-4">
                                <div
                                    class="w-10 h-10 rounded-full bg-home-primary/10 flex items-center justify-center shrink-0">
                                    <svg class="w-5 h-5 text-home-primary" fill="none" stroke="currentColor"
                                        viewBox="0 0 24 24">
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z">
                                        </path>
                                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                            d="M15 11a3 3 0 11-6 0 3 3 0 016 0z"></path>
                                    </svg>
                                </div>
                                <p class="text-lg text-home-foreground/70">{{ $selectedOutlet->address }}</p>
                            </div>
                        </div>

                        <!-- Facilities -->
                        <div>
                            <h4 class="text-sm font-bold text-home-foreground uppercase tracking-wider mb-4">Fasilitas
                            </h4>
                            <div class="flex flex-wrap gap-2">
                                @forelse($selectedOutlet->facilities as $facility)
                                    <span
                                        class="px-4 py-2 bg-home-foreground/5 rounded-xl text-sm text-home-foreground/70 border border-home-foreground/10">
                                        {{ $facility->name }}
                                    </span>
                                @empty
                                    <p class="text-sm text-home-foreground/40 italic">Tidak ada fasilitas khusus</p>
                                @endforelse
                            </div>
                        </div>

                        <!-- Opening Hours -->
                        <div>
                            <h4 class="text-sm font-bold text-home-foreground uppercase tracking-wider mb-4">Jam
                                Operasional</h4>
                            <div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
                                @php
                                    $todayEnum = now()->dayOfWeekIso === 7 ? 1 : now()->dayOfWeekIso + 1;
                                @endphp
                                @foreach ($selectedOutlet->openingHours->sortBy('day.value') as $hour)
                                    <div
                                        class="flex justify-between items-center p-3 rounded-xl border border-home-foreground/5 {{ $hour->day->value === $todayEnum ? 'bg-home-primary/5 border-home-primary/20' : '' }}">
                                        <span
                                            class="text-xs font-medium {{ $hour->day->value === $todayEnum ? 'text-home-primary font-bold' : 'text-home-foreground/60' }}">
                                            {{ $hour->day->label() }}
                                        </span>
                                        <span class="text-xs font-bold text-home-foreground">
                                            {{ \Carbon\Carbon::parse($hour->open_time)->format('H:i') }} -
                                            {{ \Carbon\Carbon::parse($hour->close_time)->format('H:i') }}
                                        </span>
                                    </div>
                                @endforeach
                            </div>
                        </div>

                        <!-- Contact & Maps -->
                        <div class="flex gap-4 pt-4">
                            <a href="tel:{{ $selectedOutlet->phone_number }}"
                                class="flex-1 py-4 rounded-2xl bg-white border border-home-foreground/10 text-home-foreground text-center font-bold hover:border-home-primary hover:text-home-primary transition-all flex items-center justify-center gap-2">
                                <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="M3 5a2 2 0 012-2h3.28a1 1 0 01.948.684l1.498 4.493a1 1 0 01-.502 1.21l-2.257 1.13a11.042 11.042 0 005.516 5.516l1.13-2.257a1 1 0 011.21-.502l4.493 1.498a1 1 0 01.684.949V19a2 2 0 01-2 2h-1C9.716 21 3 14.284 3 6V5z">
                                    </path>
                                </svg>
                                Telepon
                            </a>
                            <a href="{{ $selectedOutlet->maps_url }}" target="_blank"
                                class="flex-[1.5] py-4 rounded-2xl bg-home-primary text-white text-center font-bold hover:bg-home-secondary hover:text-home-primary transition-all shadow-lg shadow-home-primary/20 flex items-center justify-center gap-2">
                                <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 20l-5.447-2.724A1 1 0 013 16.382V5.618a1 1 0 011.447-.894L9 7m0 13l6-3m-6 3V7m6 10l4.553 2.276A1 1 0 0021 18.382V7.618a1 1 0 00-.553-.894L15 4m0 13V4m0 0L9 7">
                                    </path>
                                </svg>
                                Petunjuk Arah
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    @endif
</div>
