<div class="flex flex-col bg-home-background font-sans">

    <div class="fixed top-0 left-0 h-1 bg-home-primary z-50 transition-all duration-100" id="progressBar"
        style="width: 0%"></div>

    <main class="flex-grow pb-24 pt-36">

        <header class="px-6 lg:px-32 xl:px-48 mb-12 text-center mx-auto">
            <div
                class="flex flex-wrap items-center justify-center gap-3 mb-6 text-sm font-bold tracking-widest uppercase">
                @foreach ($article->categories 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">
                        {{ $category->name }}
                    </span>
                @endforeach
            </div>

            <h1 class="text-3xl md:text-5xl font-bold text-home-foreground mb-6 leading-tight">
                {{ $article->title }}
            </h1>
            <div class="flex items-center justify-center gap-4 text-sm text-home-foreground/60">
                <div class="flex items-center gap-2">
                    <div class="w-8 h-8 rounded-full bg-home-foreground/10 overflow-hidden">
                        <img src="https://ui-avatars.com/api/?name={{ urlencode($article->author?->employee?->full_name) }}"
                            alt="Author" class="w-full h-full object-cover">
                    </div>
                    <span>Oleh <strong
                            class="text-home-foreground">{{ $article->author?->employee?->full_name }}</strong></span>
                </div>
                <span>&bull;</span>
                <span>{{ formatDateLocalized($article->published_at) }}</span>
                <span>&bull;</span>
                <span>{{ $article->views }}x dilihat</span>
            </div>
        </header>

        <div class="px-6 lg:px-32 xl:px-48 mb-16">
            <div class="aspect-video w-full rounded-xl overflow-hidden shadow-2xl">
                <img src="{{ $article->thumbnail }}" alt="{{ $article->title }}" class="w-full h-full object-cover">
            </div>
        </div>

        <div class="px-6 lg:px-32 xl:px-48 grid grid-cols-1 lg:grid-cols-12 gap-12">

            <article class="lg:col-span-8">
                <div class="flex items-center gap-4 mb-8 pb-8 border-b border-home-foreground/10">
                    <span class="text-sm font-bold text-home-foreground">Bagikan:</span>

                    {{-- WhatsApp --}}
                    <a href="https://wa.me/?text={{ urlencode($article->title . ' ' . url()->current()) }}"
                        target="_blank" rel="noopener noreferrer"
                        class="w-10 h-10 rounded-full border border-home-foreground/10 flex items-center justify-center text-home-foreground hover:bg-home-primary hover:text-white 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>
                    </a>

                    {{-- Facebook --}}
                    <a href="https://www.facebook.com/sharer/sharer.php?u={{ urlencode(url()->current()) }}"
                        target="_blank" rel="noopener noreferrer"
                        class="w-10 h-10 rounded-full border border-home-foreground/10 flex items-center justify-center text-home-foreground hover:bg-home-primary hover:text-white 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>
                    </a>

                    {{-- X (Twitter) --}}
                    <a href="https://twitter.com/intent/tweet?text={{ urlencode($article->title) }}&url={{ urlencode(url()->current()) }}"
                        target="_blank" rel="noopener noreferrer"
                        class="w-10 h-10 rounded-full border border-home-foreground/10 flex items-center justify-center text-home-foreground hover:bg-home-primary hover:text-white 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>
                    </a>
                </div>

                <div class="prose prose-lg max-w-none text-home-foreground/80 leading-relaxed">
                    <div
                        class="first-letter:text-6xl first-letter:font-bold first-letter:text-home-primary first-letter:float-left first-letter:mr-3 first-letter:mt-[-10px] mb-8 text-home-foreground  text-justify">
                        {!! $article->content !!}
                    </div>
                </div>

                <div class="grid grid-cols-2 gap-6 mt-12">
                    @if ($previousArticle)
                        <a href="{{ route('article.show', $previousArticle->slug) }}" wire:navigate
                            class="group block p-6 border border-home-foreground/10 rounded-2xl hover:border-home-primary/30 transition-all">
                            <span
                                class="text-xs text-home-foreground/40 font-bold uppercase mb-1 block group-hover:text-home-primary">Sebelumnya</span>
                            <h4
                                class="font-bold text-home-foreground line-clamp-2 group-hover:text-home-primary transition-colors">
                                {{ $previousArticle->title }}
                            </h4>
                        </a>
                    @endif
                    @if ($nextArticle)
                        <a href="{{ route('article.show', $nextArticle->slug) }}" wire:navigate
                            class="group block p-6 border border-home-foreground/10 rounded-2xl text-right hover:border-home-primary/30 transition-all">
                            <span
                                class="text-xs text-home-foreground/40 font-bold uppercase mb-1 block group-hover:text-home-primary">Selanjutnya</span>
                            <h4
                                class="font-bold text-home-foreground line-clamp-2 group-hover:text-home-primary transition-colors">
                                {{ $nextArticle->title }}</h4>
                        </a>
                    @endif
                </div>
            </article>

            <aside class="lg:col-span-4 pl-0 lg:pl-8 border-l-0 lg:border-l border-home-foreground/5">
                <div class="sticky top-32 space-y-10">

                    <div x-data="{
                        progress: 0,
                        updateProgress() {
                            const winScroll = window.pageYOffset || document.documentElement.scrollTop
                            const height = document.documentElement.scrollHeight - document.documentElement.clientHeight
                            this.progress = height > 0 ? (winScroll / height) * 100 : 0
                        }
                    }" x-init="updateProgress();
                    window.addEventListener('scroll', updateProgress)">
                        <!-- progress bar -->
                        <div class="fixed top-0 left-0 w-full h-1 bg-transparent z-50">
                            <div class="h-full bg-home-primary transition-all duration-75"
                                :style="`width: ${progress}%`" id="progressBar"></div>
                        </div>

                        <!-- konten kamu -->
                        <div>
                            <h3 class="text-lg font-bold text-home-primary mb-6 flex items-center gap-2">
                                <span class="w-1 h-6 bg-home-primary rounded-full"></span>
                                Artikel Terbaru
                            </h3>
                            <div class="space-y-6">
                                @foreach ($latestArticles as $latest)
                                    <a href="{{ route('article.show', $latest['slug']) }}" wire:navigate
                                        class="flex gap-4 group">
                                        <div class="w-20 h-20 flex-shrink-0 rounded-xl overflow-hidden">
                                            <img src="{{ $latest['thumbnail'] }}"
                                                class="w-full h-full object-cover group-hover:scale-110 transition-transform duration-500">
                                        </div>
                                        <div>
                                            <h4
                                                class="font-bold text-home-foreground text-sm leading-snug group-hover:text-home-primary transition-colors mt-1">
                                                {{ $latest['title'] }}
                                            </h4>
                                            <span class="text-xs text-home-foreground/50 mt-2 block">
                                                {{ formatDateLocalized($latest['published_at']) }}
                                            </span>
                                            <span class="text-xs text-home-foreground/40 font-bold">
                                                {{ $latest['views'] }}x dilihat
                                            </span>
                                        </div>
                                    </a>
                                @endforeach
                            </div>
                        </div>
                    </div>

                    {{-- Not used yet --}}
                    {{-- <section
                        class="bg-home-primary rounded-2xl p-8 text-center relative overflow-hidden group shadow-lg shadow-home-primary/20">
                        <div
                            class="absolute top-0 right-0 w-32 h-32 bg-home-secondary/20 rounded-full blur-2xl -mr-10 -mt-10">
                        </div>

                        <div class="relative z-10">
                            <div
                                class="w-12 h-12 bg-white/10 rounded-full flex items-center justify-center mx-auto mb-4 text-white">
                                <svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                        d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z">
                                    </path>
                                </svg>
                            </div>
                            <h3 class="text-xl font-bold text-white mb-2">Newsletter</h3>
                            <p class="text-sm text-white/80 mb-6 leading-relaxed">Dapatkan tips eksklusif dan artikel
                                terbaru langsung ke email Anda.</p>

                            <form onsubmit="event.preventDefault();" class="space-y-3">
                                <input type="email" placeholder="Email Anda..." required aria-label="Alamat Email"
                                    class="w-full py-3 px-4 rounded-xl border border-white/20 bg-white/10 text-white placeholder-white/50 text-sm focus:outline-none focus:bg-white/20 focus:border-home-secondary transition-all">
                                <button type="submit"
                                    class="w-full bg-home-secondary text-home-primary font-bold py-3 rounded-xl hover:bg-white transition-all duration-300 text-sm shadow-lg">Subscribe</button>
                            </form>
                        </div>
                    </section> --}}

                </div>
            </aside>

        </div>

    </main>
</div>

@script
    <script>
        window.onscroll = function() {
            let winScroll = document.body.scrollTop || document.documentElement.scrollTop;
            let height = document.documentElement.scrollHeight - document.documentElement.clientHeight;
            let scrolled = (winScroll / height) * 100;
            document.getElementById("progressBar").style.width = scrolled + "%";
        };
    </script>
@endscript

@assets
    <style>
        .prose p:empty {
            min-height: 1.25rem;
        }
    </style>
@endassets
