"use client";

import { useState, useEffect } from "react";
import Link from "next/link";
import { usePathname } from "next/navigation";
import { Button } from "@/components/ui/button";
import { Sheet, SheetContent, SheetTrigger } from "@/components/ui/sheet";
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion";
import { Menu, Home, User, Landmark, Briefcase, Calendar, FolderOpen, Newspaper, ImageIcon, Lock } from "lucide-react";
import { fetchAcaraAktif } from "@/lib/public-actions";

import { SessionProvider, useSession } from "next-auth/react";

function PublicLayoutContent({
    children,
}: {
    children: React.ReactNode;
}) {
    const [isDarkNav, setIsDarkNav] = useState(false);
    const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false);
    const [acaraAktif, setAcaraAktif] = useState<any[]>([]);
    const { data: session } = useSession();
    const pathname = usePathname();

    useEffect(() => {
        const handleScroll = () => {
            const currentScroll = window.scrollY;
            
            // Gunakan getBoundingClientRect untuk mendeteksi apakah navbar (ketinggian sekitar 0 - 80px)
            // sedang melayang di atas section yang memiliki data-theme="dark"
            const darkSections = document.querySelectorAll('[data-theme="dark"]');
            let isOverDark = false;
            
            darkSections.forEach(section => {
                const rect = section.getBoundingClientRect();
                // Jika posisi atas section telah mencapai / melewati bagian bawah navbar (sekitar 60-80px)
                // dan bagian bawah section belum melewati bagian atas viewport
                if (rect.top <= 80 && rect.bottom >= 20) {
                    isOverDark = true;
                }
            });
            
            if (pathname === '/') {
                // Di homepage, area Hero juga dianggap dark (sekitar 80vh tinggi)
                if (currentScroll < window.innerHeight * 0.8) {
                    setIsDarkNav(true);
                } else {
                    setIsDarkNav(isOverDark);
                }
            } else {
                setIsDarkNav(isOverDark);
            }
        };

        window.addEventListener("scroll", handleScroll, { passive: true });
        // Set awal
        handleScroll();

        // Fetch acara aktif
        fetchAcaraAktif().then(data => setAcaraAktif((data as any[]) || [])).catch(() => {});

        return () => window.removeEventListener("scroll", handleScroll);
    }, [pathname]);

    const handleMobileLinkClick = (e: React.MouseEvent) => {
        const target = e.target as HTMLElement;
        if (target.closest('a')) {
            setIsMobileMenuOpen(false);
        }
    };

    return (
        <div className="flex min-h-screen flex-col relative">
            {/* Header / Navbar Interaktif */}
            <header className="fixed top-0 z-50 w-full flex justify-center pt-4 px-4 pointer-events-none">
                <div className="pointer-events-auto w-full max-w-[1100px]">
                <div className={`flex h-16 items-center justify-between px-6 rounded-2xl border transition-all duration-300 ${
                    isDarkNav 
                    ? 'bg-white/5 backdrop-blur-2xl border-white/10 shadow-[0_8px_32px_rgba(0,0,0,0.3)]' 
                    : 'bg-white/85 backdrop-blur-2xl border-gray-200/50 shadow-[0_8px_30px_rgba(0,0,0,0.06)]'
                }`}>
                    <Link href="/" className="flex items-center space-x-3 group shrink-0 pr-4">
                        {/* eslint-disable-next-line @next/next/no-img-element */}
                        <img src="/logo.png" alt="Logo HMF" className="w-9 h-9 object-contain group-hover:scale-105 transition-transform drop-shadow-md" />
                        <span className={`font-bold text-[15px] tracking-wide transition-colors ${isDarkNav ? 'text-white' : 'text-[#0B1F3A]'}`}>
                            Himpunan Mahasiswa Fisika
                        </span>
                    </Link>

                    {/* Desktop Navigation */}
                    <nav className="hidden lg:flex items-center space-x-6">
                        {/* Dropdown Profil */}
                        <div className="group relative cursor-pointer py-4">
                            <Link href="/profil" className={`text-sm font-semibold tracking-wide transition-all hover:text-[#3b82f6] ${isDarkNav ? 'text-white/90' : 'text-[#0B1F3A]/80'}`}>
                                Profil
                            </Link>

                            {/* Dropdown Menu Content */}
                            <div className="absolute top-full left-0 mt-2 w-52 opacity-0 translate-y-2 invisible group-hover:opacity-100 group-hover:translate-y-0 group-hover:visible transition-all duration-300 z-50">
                                <div className="bg-[#0a0f1e]/80 backdrop-blur-3xl rounded-xl shadow-[0_8px_40px_rgba(0,0,0,0.6)] border border-white/15 overflow-hidden py-1.5 flex flex-col">
                                    <Link href="/profil?tab=sejarah" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Sejarah Singkat</Link>
                                    <Link href="/profil?tab=lambang" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Lambang HMF</Link>
                                    <Link href="/profil?tab=mars" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Mars dan Hymne HMF</Link>
                                </div>
                            </div>
                        </div>

                        {/* Dropdown Kabinet */}
                        <div className="group relative cursor-pointer py-4">
                            <Link href="/kabinet" className={`text-sm font-semibold tracking-wide transition-all hover:text-[#3b82f6] ${isDarkNav ? 'text-white/90' : 'text-[#0B1F3A]/80'}`}>
                                Kabinet
                            </Link>

                            <div className="absolute top-full left-0 mt-2 w-52 opacity-0 translate-y-2 invisible group-hover:opacity-100 group-hover:translate-y-0 group-hover:visible transition-all duration-300 z-50">
                                <div className="bg-[#0a0f1e]/80 backdrop-blur-3xl rounded-xl shadow-[0_8px_40px_rgba(0,0,0,0.6)] border border-white/15 overflow-hidden py-1.5 flex flex-col">
                                    <Link href="/kabinet?tab=visi-misi" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Visi & Misi</Link>
                                    <Link href="/kabinet?tab=lambang" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Lambang Kabinet</Link>
                                    <Link href="/kabinet?tab=profil" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Profil Kabinet</Link>
                                    <Link href="/kabinet?tab=organigram" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Organigram PH</Link>
                                </div>
                            </div>
                        </div>

                        {/* Dropdown Parlemen */}
                        <div className="group relative cursor-pointer py-4">
                            <Link href="/parlemen" className={`text-sm font-semibold tracking-wide transition-all hover:text-[#3b82f6] ${isDarkNav ? 'text-white/90' : 'text-[#0B1F3A]/80'}`}>
                                Parlemen
                            </Link>

                            <div className="absolute top-full left-0 mt-2 w-64 opacity-0 translate-y-2 invisible group-hover:opacity-100 group-hover:translate-y-0 group-hover:visible transition-all duration-300 z-50">
                                <div className="bg-[#0a0f1e]/80 backdrop-blur-3xl rounded-xl shadow-[0_8px_40px_rgba(0,0,0,0.6)] border border-white/15 overflow-hidden py-1.5 flex flex-col">
                                    <Link prefetch={false} href="/parlemen?tab=profil-parlemen" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Profil Parlemen</Link>
                                    <Link prefetch={false} href="/parlemen?tab=produk-mumas" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Produk Mumas</Link>
                                    <Link prefetch={false} href="/parlemen?tab=organigram" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Organigram DPM</Link>
                                </div>
                            </div>
                        </div>

                        {/* Dropdown Program Kerja */}
                        <div className="group relative cursor-pointer py-4">
                            <Link href="/program-kerja" className={`text-sm font-semibold tracking-wide transition-all hover:text-[#3b82f6] ${isDarkNav ? 'text-white/90' : 'text-[#0B1F3A]/80'}`}>
                                Program Kerja
                            </Link>

                            <div className="absolute top-full left-1/2 -translate-x-1/2 mt-2 w-[460px] opacity-0 translate-y-2 invisible group-hover:opacity-100 group-hover:translate-y-0 group-hover:visible transition-all duration-300 z-50">
                                <div className="bg-[#0a0f1e]/80 backdrop-blur-3xl rounded-xl shadow-[0_8px_40px_rgba(0,0,0,0.6)] border border-white/15 p-3 grid grid-cols-2 gap-x-2 gap-y-0.5">
                                    <Link href="/program-kerja/lembaga-kesekretariatan" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">Lembaga Kesekretariatan</Link>
                                    <Link href="/program-kerja/lembaga-keuangan" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">Lembaga Keuangan</Link>
                                    <Link href="/program-kerja/bidang-akademik" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">Bidang Akademik</Link>
                                    <Link href="/program-kerja/bidang-ekonomi-dan-bisnis" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">B. Ekonomi & Bisnis</Link>
                                    <Link href="/program-kerja/bidang-kaderisasi" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">Bidang Kaderisasi</Link>
                                    <Link href="/program-kerja/bidang-kerohanian" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">Bidang Kerohanian</Link>
                                    <Link href="/program-kerja/bidang-komunikasi-dan-media-informasi" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">B. Kominfo</Link>
                                    <Link href="/program-kerja/bidang-penelitian-dan-pengembangan" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">B. Litbang</Link>
                                    <Link href="/program-kerja/bidang-pengembangan-minat-dan-bakat" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">B. Minat Bakat</Link>
                                    <Link href="/program-kerja/bidang-sosial-dan-politik" className="px-3 py-2 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white rounded-lg font-medium transition-colors">Bidang Sospol</Link>
                                </div>
                            </div>
                        </div>
                        {/* Dropdown UKK */}
                        <div className="group relative cursor-pointer py-4">
                            <Link href="/ukk" className={`text-sm font-semibold tracking-wide transition-all hover:text-[#3b82f6] ${isDarkNav ? 'text-white/90' : 'text-[#0B1F3A]/80'}`}>
                                UKK
                            </Link>
                            <div className="absolute top-full left-0 mt-2 w-48 opacity-0 translate-y-2 invisible group-hover:opacity-100 group-hover:translate-y-0 group-hover:visible transition-all duration-300 z-50">
                                <div className="bg-[#0a0f1e]/80 backdrop-blur-3xl rounded-xl shadow-[0_8px_40px_rgba(0,0,0,0.6)] border border-white/15 overflow-hidden py-1.5 flex flex-col">
                                    <Link href="/ukk/cakrawala" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">UKK Cakrawala</Link>
                                    <Link href="/ukk/khauf" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">UKK Khauf</Link>
                                </div>
                            </div>
                        </div>

                        {/* Dropdown Acara */}
                        <div className="group relative cursor-pointer py-4">
                            <Link href="/acara" className={`text-sm font-semibold tracking-wide transition-all hover:text-[#3b82f6] ${isDarkNav ? 'text-white/90' : 'text-[#0B1F3A]/80'}`}>
                                Acara
                            </Link>

                            {acaraAktif.length > 0 && (
                                <div className="absolute top-full left-0 mt-2 w-48 opacity-0 translate-y-2 invisible group-hover:opacity-100 group-hover:translate-y-0 group-hover:visible transition-all duration-300 z-50">
                                    <div className="bg-[#0a0f1e]/80 backdrop-blur-3xl rounded-xl shadow-[0_8px_40px_rgba(0,0,0,0.6)] border border-white/15 overflow-hidden py-1.5 flex flex-col">
                                        {acaraAktif.map(acara => (
                                            <Link key={acara.id} href={`/acara/${acara.slug}`} className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">
                                                {acara.slug}
                                            </Link>
                                        ))}
                                    </div>
                                </div>
                            )}
                        </div>

                        {/* Dropdown Konten */}
                        <div className="group relative cursor-pointer py-4">
                            <Link href="/konten" className={`text-sm font-semibold tracking-wide transition-all hover:text-[#3b82f6] ${isDarkNav ? 'text-white/90' : 'text-[#0B1F3A]/80'}`}>
                                Konten
                            </Link>

                            <div className="absolute top-full left-0 mt-2 w-48 opacity-0 translate-y-2 invisible group-hover:opacity-100 group-hover:translate-y-0 group-hover:visible transition-all duration-300 z-50">
                                <div className="bg-[#0a0f1e]/80 backdrop-blur-3xl rounded-xl shadow-[0_8px_40px_rgba(0,0,0,0.6)] border border-white/15 overflow-hidden py-1.5 flex flex-col">
                                    <Link href="/konten/bearr" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">BEARR</Link>
                                    <Link href="/konten/kinetik" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">KINETIK</Link>
                                    <Link href="/konten/link-shortener" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">LASER</Link>
                                </div>
                            </div>
                        </div>

                        {/* Dropdown Media */}
                        <div className="group relative cursor-pointer py-4">
                            <Link href="/media" className={`text-sm font-semibold tracking-wide transition-all hover:text-[#3b82f6] ${isDarkNav ? 'text-white/90' : 'text-[#0B1F3A]/80'}`}>
                                Media
                            </Link>

                            <div className="absolute top-full left-0 mt-2 w-52 opacity-0 translate-y-2 invisible group-hover:opacity-100 group-hover:translate-y-0 group-hover:visible transition-all duration-300 z-50">
                                <div className="bg-[#0a0f1e]/80 backdrop-blur-3xl rounded-xl shadow-[0_8px_40px_rgba(0,0,0,0.6)] border border-white/15 overflow-hidden py-1.5 flex flex-col">
                                    <Link href="/galeri" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Galeri</Link>
                                    <Link href="/berita" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Berita HMF</Link>
                                    <Link href="/prestasi" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Prestasi</Link>
                                    <Link href="/rangers-talk" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Rangers Talk</Link>
                                    <Link href="/laporan-keuangan" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Laporan Keuangan</Link>
                                    <Link href="/awardee" className="px-4 py-2.5 text-sm text-white/80 hover:bg-[#3b82f6]/20 hover:text-white font-medium transition-colors">Awardee PH</Link>
                                </div>
                            </div>
                        </div>
                        {session?.user ? (
                            <Link href="/admin" className={`py-2 px-5 rounded-xl text-xs font-bold tracking-wide transition-all shadow-sm border border-transparent ${isDarkNav ? 'bg-white text-[#111] hover:bg-gray-100' : 'bg-[#0B1F3A] text-white hover:bg-[#0B1F3A]/90'}`}>Dashboard</Link>
                        ) : (
                            <Link href="/login" className={`py-2 px-5 rounded-xl text-xs font-bold tracking-wide transition-all shadow-sm border border-transparent ${isDarkNav ? 'bg-white text-[#111] hover:bg-gray-100' : 'bg-[#0B1F3A] text-white hover:bg-[#0B1F3A]/90'}`}>Login</Link>
                        )}
                    </nav>
                </div>
                </div>
            </header>

            {/* Mobile Bottom Navigation */}
            <div className="lg:hidden fixed bottom-0 left-0 right-0 bg-[#0a0f1e]/70 backdrop-blur-3xl border-t border-white/10 z-50 pb-safe shadow-[0_-8px_30px_rgba(0,0,0,0.3)]">
                <div className="flex items-center justify-around h-[4.5rem]">
                    <Link href="/" onClick={() => setIsMobileMenuOpen(false)} className={`flex flex-col items-center justify-center w-full h-full space-y-1 transition-colors ${pathname === '/' ? 'text-blue-400' : 'text-gray-400 hover:text-white'}`}>
                        <Home className="w-6 h-6" />
                        <span className="text-[10px] font-medium">Beranda</span>
                    </Link>
                    <Link href="/profil" onClick={() => setIsMobileMenuOpen(false)} className={`flex flex-col items-center justify-center w-full h-full space-y-1 transition-colors ${pathname.startsWith('/profil') ? 'text-blue-400' : 'text-gray-400 hover:text-white'}`}>
                        <User className="w-6 h-6" />
                        <span className="text-[10px] font-medium">Profil</span>
                    </Link>
                    <Link href="/kabinet" onClick={() => setIsMobileMenuOpen(false)} className={`flex flex-col items-center justify-center w-full h-full space-y-1 transition-colors ${pathname.startsWith('/kabinet') ? 'text-blue-400' : 'text-gray-400 hover:text-white'}`}>
                        <Landmark className="w-6 h-6" />
                        <span className="text-[10px] font-medium">Kabinet</span>
                    </Link>
                    <Link href="/program-kerja" onClick={() => setIsMobileMenuOpen(false)} className={`flex flex-col items-center justify-center w-full h-full space-y-1 transition-colors ${pathname.startsWith('/program-kerja') ? 'text-blue-400' : 'text-gray-400 hover:text-white'}`}>
                        <Briefcase className="w-6 h-6" />
                        <span className="text-[10px] font-medium">Proker</span>
                    </Link>
                    
                    <Sheet open={isMobileMenuOpen} onOpenChange={setIsMobileMenuOpen}>
                        <SheetTrigger asChild>
                            <button className={`flex flex-col items-center justify-center w-full h-full space-y-1 transition-colors ${isMobileMenuOpen ? 'text-blue-400' : 'text-gray-400 hover:text-white'}`}>
                                <Menu className="w-6 h-6" />
                                <span className="text-[10px] font-medium">Lengkap</span>
                            </button>
                        </SheetTrigger>
                        <SheetContent side="bottom" showCloseButton={true} className="h-[85vh] rounded-t-3xl bg-[#0a0f1e]/60 backdrop-blur-3xl text-white border-t border-white/20 p-0 overflow-hidden flex flex-col shadow-[0_-10px_50px_rgba(0,0,0,0.5)]">
                            <div className="flex flex-col h-full w-full py-8 px-6 relative z-10 overflow-y-auto">
                                <Link href="/" className="flex items-center space-x-3 mb-8" onClick={() => setIsMobileMenuOpen(false)}>
                                    {/* eslint-disable-next-line @next/next/no-img-element */}
                                    <img src="/logo.png" alt="Logo HMF" className="w-10 h-10 object-contain drop-shadow-md" />
                                    <span className="font-bold text-xl tracking-wide uppercase text-white">HMF FPMIPA UPI</span>
                                </Link>

                                <nav className="flex flex-col space-y-2 mt-2 flex-1" onClick={handleMobileLinkClick}>
                                    <Link href="/" className="flex items-center gap-4 py-3 px-3 rounded-xl hover:bg-white/10 text-lg font-medium transition-colors border border-transparent hover:border-white/10">
                                        <Home className="w-5 h-5 text-blue-400" /> Beranda
                                    </Link>

                                    <Accordion type="single" collapsible className="w-full space-y-2">
                                        {/* Accordion Profil */}
                                        <AccordionItem value="profil" className="border-b-0 space-y-1 bg-white/5 rounded-2xl px-2">
                                            <AccordionTrigger className="hover:bg-white/5 hover:no-underline rounded-xl px-3 py-3 data-[state=open]:bg-white/5 transition-colors">
                                                <div className="flex items-center gap-4 text-lg font-medium">
                                                    <User className="w-5 h-5 text-blue-400" /> Profil HMF
                                                </div>
                                            </AccordionTrigger>
                                            <AccordionContent className="pl-12 pr-4 pb-4 space-y-3 pt-2">
                                                <Link href="/profil?tab=sejarah" className="block text-base text-gray-300 hover:text-white transition-colors">Sejarah Singkat</Link>
                                                <Link href="/profil?tab=lambang" className="block text-base text-gray-300 hover:text-white transition-colors">Lambang HMF</Link>
                                                <Link href="/profil?tab=mars" className="block text-base text-gray-300 hover:text-white transition-colors">Mars dan Hymne</Link>
                                                <Link href="/profil?tab=ukk" className="block text-base text-gray-300 hover:text-white transition-colors">Unit Kegiatan Khusus</Link>
                                            </AccordionContent>
                                        </AccordionItem>

                                        {/* Accordion Kabinet */}
                                        <AccordionItem value="kabinet" className="border-b-0 space-y-1 bg-white/5 rounded-2xl px-2">
                                            <AccordionTrigger className="hover:bg-white/5 hover:no-underline rounded-xl px-3 py-3 data-[state=open]:bg-white/5 transition-colors">
                                                <div className="flex items-center gap-4 text-lg font-medium">
                                                    <Landmark className="w-5 h-5 text-blue-400" /> Kabinet
                                                </div>
                                            </AccordionTrigger>
                                            <AccordionContent className="pl-12 pr-4 pb-4 space-y-3 pt-2">
                                                <Link href="/kabinet?tab=visi-misi" className="block text-base text-gray-300 hover:text-white transition-colors">Visi & Misi</Link>
                                                <Link href="/kabinet?tab=lambang" className="block text-base text-gray-300 hover:text-white transition-colors">Lambang Kabinet</Link>
                                                <Link href="/kabinet?tab=profil" className="block text-base text-gray-300 hover:text-white transition-colors">Profil Kabinet</Link>
                                                <Link href="/kabinet?tab=organigram" className="block text-base text-gray-300 hover:text-white transition-colors">Organigram PH</Link>
                                            </AccordionContent>
                                        </AccordionItem>

                                        {/* Accordion Parlemen */}
                                        <AccordionItem value="parlemen" className="border-b-0 space-y-1 bg-white/5 rounded-2xl px-2">
                                            <AccordionTrigger className="hover:bg-white/5 hover:no-underline rounded-xl px-3 py-3 data-[state=open]:bg-white/5 transition-colors">
                                                <div className="flex items-center gap-4 text-lg font-medium">
                                                    <Newspaper className="w-5 h-5 text-blue-400" /> Parlemen
                                                </div>
                                            </AccordionTrigger>
                                            <AccordionContent className="pl-12 pr-4 pb-4 space-y-3 pt-2">
                                                <Link prefetch={false} href="/parlemen?tab=profil-parlemen" className="block text-base text-gray-300 hover:text-white transition-colors">Profil Parlemen</Link>
                                                <Link prefetch={false} href="/parlemen?tab=produk-mumas" className="block text-base text-gray-300 hover:text-white transition-colors">Produk Mumas</Link>
                                                <Link prefetch={false} href="/parlemen?tab=organigram" className="block text-base text-gray-300 hover:text-white transition-colors">Organigram DPM</Link>
                                            </AccordionContent>
                                        </AccordionItem>

                                        {/* Accordion Program Kerja */}
                                        <AccordionItem value="proker" className="border-b-0 space-y-1 bg-white/5 rounded-2xl px-2">
                                            <AccordionTrigger className="hover:bg-white/5 hover:no-underline rounded-xl px-3 py-3 data-[state=open]:bg-white/5 transition-colors">
                                                <div className="flex items-center gap-4 text-lg font-medium">
                                                    <Briefcase className="w-5 h-5 text-blue-400" /> Program Kerja
                                                </div>
                                            </AccordionTrigger>
                                            <AccordionContent className="pl-12 pr-4 pb-4 space-y-3 pt-2">
                                                <Link href="/program-kerja" className="block py-2 text-sm font-bold text-blue-300 mb-2 bg-blue-500/10 rounded-lg text-center border border-blue-500/20">Lihat Semua Proker →</Link>
                                                <Link href="/program-kerja/lembaga-kesekretariatan" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">L. Kesekretariatan</Link>
                                                <Link href="/program-kerja/lembaga-keuangan" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">L. Keuangan</Link>
                                                <Link href="/program-kerja/bidang-akademik" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">B. Akademik</Link>
                                                <Link href="/program-kerja/bidang-ekonomi-dan-bisnis" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">B. Ekonomi Bisnis</Link>
                                                <Link href="/program-kerja/bidang-kaderisasi" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">B. Kaderisasi</Link>
                                                <Link href="/program-kerja/bidang-kerohanian" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">B. Kerohanian</Link>
                                                <Link href="/program-kerja/bidang-komunikasi-dan-media-informasi" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">B. Kominfo</Link>
                                                <Link href="/program-kerja/bidang-penelitian-dan-pengembangan" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">B. Litbang</Link>
                                                <Link href="/program-kerja/bidang-pengembangan-minat-dan-bakat" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">B. Minat Bakat</Link>
                                                <Link href="/program-kerja/bidang-sosial-dan-politik" className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">B. Sospol</Link>
                                            </AccordionContent>
                                        </AccordionItem>

                                        {/* Accordion Acara */}
                                        {acaraAktif.length > 0 ? (
                                            <AccordionItem value="acara" className="border-b-0 space-y-1 bg-white/5 rounded-2xl px-2">
                                                <AccordionTrigger className="hover:bg-white/5 hover:no-underline rounded-xl px-3 py-3 data-[state=open]:bg-white/5 transition-colors">
                                                    <div className="flex items-center gap-4 text-lg font-medium">
                                                        <Calendar className="w-5 h-5 text-blue-400" /> Acara
                                                    </div>
                                                </AccordionTrigger>
                                                <AccordionContent className="pl-12 pr-4 pb-4 space-y-3 pt-2">
                                                    <Link href="/acara" className="block py-2 text-sm font-bold text-blue-300 mb-2 bg-blue-500/10 rounded-lg text-center border border-blue-500/20">Semua Acara →</Link>
                                                    {acaraAktif.map(acara => (
                                                        <Link key={acara.id} href={`/acara/${acara.slug}`} className="block py-1 text-sm text-gray-300 hover:text-white transition-colors">
                                                            {acara.slug}
                                                        </Link>
                                                    ))}
                                                </AccordionContent>
                                            </AccordionItem>
                                        ) : (
                                            <div className="px-3 py-3 rounded-xl hover:bg-white/5 transition-colors bg-white/5 mt-2">
                                                <Link href="/acara" className="flex items-center gap-4 text-lg font-medium text-white px-2">
                                                    <Calendar className="w-5 h-5 text-blue-400" /> Acara
                                                </Link>
                                            </div>
                                        )}

                                        {/* Accordion Konten */}
                                        <AccordionItem value="konten" className="border-b-0 space-y-1 bg-white/5 rounded-2xl px-2">
                                            <AccordionTrigger className="hover:bg-white/5 hover:no-underline rounded-xl px-3 py-3 data-[state=open]:bg-white/5 transition-colors">
                                                <div className="flex items-center gap-4 text-lg font-medium">
                                                    <FolderOpen className="w-5 h-5 text-blue-400" /> Konten
                                                </div>
                                            </AccordionTrigger>
                                            <AccordionContent className="pl-12 pr-4 pb-4 space-y-3 pt-2">
                                                <Link href="/konten" className="block py-2 text-sm font-bold text-blue-300 mb-2 bg-blue-500/10 rounded-lg text-center border border-blue-500/20">Lihat Semua Konten →</Link>
                                                <Link href="/konten/bearr" className="block text-base text-gray-300 hover:text-white transition-colors">BEARR</Link>
                                                <Link href="/konten/kinetik" className="block text-base text-[#F0C14B] hover:text-white transition-colors font-medium">KINETIK</Link>
                                                <Link href="/konten/link-shortener" className="block text-base text-gray-300 hover:text-white transition-colors">LASER</Link>
                                            </AccordionContent>
                                        </AccordionItem>
                                        
                                        {/* Accordion Media */}
                                        <AccordionItem value="media" className="border-b-0 space-y-1 bg-white/5 rounded-2xl px-2">
                                            <AccordionTrigger className="hover:bg-white/5 hover:no-underline rounded-xl px-3 py-3 data-[state=open]:bg-white/5 transition-colors">
                                                <div className="flex items-center gap-4 text-lg font-medium">
                                                    <ImageIcon className="w-5 h-5 text-blue-400" /> Media
                                                </div>
                                            </AccordionTrigger>
                                            <AccordionContent className="pl-12 pr-4 pb-4 space-y-3 pt-2">
                                                <Link href="/media" className="block py-2 text-sm font-bold text-blue-300 mb-2 bg-blue-500/10 rounded-lg text-center border border-blue-500/20">Lihat Semua Media →</Link>
                                                <Link href="/galeri" className="block text-base text-gray-300 hover:text-white transition-colors">Galeri</Link>
                                                <Link href="/berita" className="block text-base text-gray-300 hover:text-white transition-colors">Berita HMF</Link>
                                                <Link href="/prestasi" className="block text-base text-gray-300 hover:text-white transition-colors">Prestasi</Link>
                                                <Link href="/rangers-talk" className="block text-base text-gray-300 hover:text-white transition-colors">Rangers Talk</Link>
                                                <Link href="/laporan-keuangan" className="block text-base text-gray-300 hover:text-white transition-colors">Laporan Keuangan</Link>
                                                <Link href="/awardee" className="block text-base text-gray-300 hover:text-white transition-colors">Awardee PH</Link>
                                            </AccordionContent>
                                        </AccordionItem>
                                    </Accordion>

                                    {/* Link Admin */}
                                    <div className="pt-8 pb-10 mt-auto">
                                        {session?.user ? (
                                            <Link href="/admin" className="flex items-center justify-center gap-3 w-full py-4 px-4 bg-blue-600 hover:bg-blue-500 text-white rounded-2xl font-bold shadow-[0_4px_20px_rgba(59,130,246,0.4)] transition-all">
                                                <Home className="w-5 h-5" /> Buka Dashboard
                                            </Link>
                                        ) : (
                                            <Link href="/login" className="flex items-center justify-center gap-3 w-full py-4 px-4 bg-white/10 hover:bg-white/20 text-white rounded-2xl font-bold border border-white/20 transition-all">
                                                <Lock className="w-5 h-5" /> Login Admin
                                            </Link>
                                        )}
                                    </div>
                                </nav>
                            </div>
                        </SheetContent>
                    </Sheet>
                </div>
            </div>
            
            <main className="flex-1 shrink-0 bg-gray-50">{children}</main>

            <footer className="border-t py-6 md:py-0 bg-muted/20">
                <div className="container flex flex-col items-center justify-between gap-4 md:h-16 md:flex-row">
                    <p className="text-sm leading-loose text-center text-muted-foreground md:text-left">
                        &copy; {new Date().getFullYear()} Himpunan Mahasiswa FPMIPA UPI. All rights reserved.
                    </p>
                </div>
            </footer>
        </div >
    );
}

export default function PublicLayout({
    children,
}: {
    children: React.ReactNode;
}) {
    return (
        <SessionProvider>
            <PublicLayoutContent>{children}</PublicLayoutContent>
        </SessionProvider>
    );
}
