'use client'; import { Fragment } from 'react'; import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react'; import { ChevronDownIcon } from '@zen/core/shared/icons'; import { useRouter } from 'next/navigation'; import { useTheme, getThemeIcon } from '@zen/core/themes'; const AdminHeader = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appName = 'ZEN' }) => { const router = useRouter(); const getImageUrl = (imageKey) => { if (!imageKey) return null; return `/zen/api/storage/${imageKey}`; }; const handleLogout = async () => { try { if (onLogout) { const result = await onLogout(); if (result && result.success) { router.push('/auth/login'); } else { console.error('Logout failed:', result?.error); router.push('/auth/login'); } } else { router.push('/auth/login'); } } catch (error) { console.error('Logout error:', error); router.push('/auth/login'); } }; const getUserInitials = (name) => { if (!name) return 'U'; return name .split(' ') .map(n => n[0]) .join('') .toUpperCase() .slice(0, 2); }; const { theme, toggle, systemIsDark } = useTheme(); const ThemeIcon = getThemeIcon(theme, systemIsDark); const themeLabel = theme === 'light' ? 'Mode clair' : theme === 'dark' ? 'Mode sombre' : 'Thème système'; const quickLinks = []; const imageUrl = getImageUrl(user?.image); const userInitials = getUserInitials(user?.name); return (
{/* Left section — Mobile menu button + Logo */}

{appName}

{/* Right section — Quick links + Profile */}
{/* User Profile Menu */} {/* Avatar */} {imageUrl ? ( {user?.name ) : (
{userInitials}
)} {/* Name — desktop only */} {user?.name || 'User'}
{/* User info */}
{imageUrl ? ( {user?.name ) : (
{userInitials}
)}

{user?.name || user?.email || 'User'}

{user?.name && (

{user.email}

)}
{/* Quick links — mobile only */} {quickLinks.length > 0 && ( <> {quickLinks.map((link) => ( {link.name} ))}
)} {/* Profile */} Mon profil {/* Theme — pas de MenuItem pour ne pas fermer le menu au clic */}
{/* Logout */}
); }; export default AdminHeader;