// components/admin/dashboard/Sidebar.tsx - Modern Editorial Design 'use client'; import { useCallback, useMemo, useState, memo } from 'react'; import Link from 'next/link'; import { usePathname } from 'next/navigation'; import { Home, Users, Settings, X, Package, PlusCircle, Layout, LogOut, Plug, Database, FileText, ChevronRight, Sparkles, Circle, Dot, Crown, Zap } from 'lucide-react'; import { cn } from '@/lib/utils'; import { Button } from '@/components/ui/button'; import { useAuth } from '@/hooks/use-auth'; import { useCurrentUser } from '@/hooks/use-current-user'; type AdminRoute = string; interface SidebarProps { isOpen: boolean; onClose: () => void; onToggle?: () => void; } function SidebarComponent({ isOpen, onClose, onToggle }: SidebarProps) { const pathname = usePathname(); const { handleLogout } = useAuth(); const { user, isLoading: userLoading } = useCurrentUser(); const MenuItem = useCallback(({ href, icon: Icon, label, isActive, hasSubmenu = false, index = 0 }: { href: AdminRoute; icon: React.ElementType; label: string; isActive: boolean; hasSubmenu?: boolean; index?: number; }) => { return ( { if (typeof window !== 'undefined' && window.innerWidth < 768) { onClose(); } }} >
{/* Editorial Icon */} {label}
{/* Editorial Navigation Indicators */}
{hasSubmenu && ( )} {isActive && !hasSubmenu && (
)}
); }, [pathname, onClose]); const navigationSections = useMemo(() => [ { title: "Principal", items: [ { href: '/admin/dashboard', icon: Home, label: 'Dashboard' } ] }, { title: "Gestión", items: [ { href: '/admin/dashboard/users', icon: Users, label: 'Usuarios' }, { href: '/admin/dashboard/templates', icon: Layout, label: 'Plantillas' }, { href: '/admin/dashboard/content-types', icon: Database, label: 'Tipos de Contenido' }, { href: '/admin/dashboard/view-content', icon: FileText, label: 'Ver Contenido' } ] }, { title: "Sistema", items: [ { href: '/admin/dashboard/plugins', icon: Plug, label: 'Plugins' }, { href: '/admin/dashboard/settings', icon: Settings, label: 'Configuración' } ] } ], []); const handleLogoutClick = async () => { try { await handleLogout(); } catch (error) { console.error('Error al cerrar sesión:', error); } }; return ( <> {/* Enhanced Mobile Overlay */} {isOpen && (
)} {/* Editorial Sidebar */} ); } export const Sidebar = memo(SidebarComponent);