'use client'; import { Fragment } from 'react'; import { Menu, MenuButton, MenuItem, MenuItems, Transition } from '@headlessui/react'; import { ChevronDownIcon, User03Icon, DashboardSquare03Icon } from '@zen/core/shared/icons'; import { UserAvatar } from '@zen/core/shared/components'; import { useRouter, usePathname } from 'next/navigation'; import { getPage, getPages } from '../registry.js'; import { useTheme, getThemeIcon } from '@zen/core/themes'; const AdminTop = ({ isMobileMenuOpen, setIsMobileMenuOpen, user, onLogout, appName = 'ZEN', navigationSections = [] }) => { const router = useRouter(); const pathname = usePathname(); 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 { theme, toggle, systemIsDark } = useTheme(); const ThemeIcon = getThemeIcon(theme, systemIsDark); const themeLabel = theme === 'light' ? 'Mode clair' : theme === 'dark' ? 'Mode sombre' : 'Thème système'; const buildBreadcrumbs = () => { const crumbs = [{ icon: DashboardSquare03Icon, href: '/admin/dashboard' }]; const after = pathname.replace(/^\/admin\/?/, ''); if (!after) { crumbs.push({ label: getPage('dashboard')?.title }); return crumbs; } const segments = after.split('/').filter(Boolean); if (!segments.length || (segments[0] === 'dashboard' && segments.length === 1)) { crumbs.push({ label: getPage('dashboard')?.title }); return crumbs; } const [first, second] = segments; if (first === 'profile') { crumbs.push({ label: getPage('profile')?.title }); return crumbs; } const allItems = navigationSections.flatMap(s => s.items); const navItem = allItems.find(item => item.href.replace('/admin/', '').split('/')[0] === first); const hasSubPage = segments.length > 1; if (navItem) { crumbs.push({ label: navItem.name, href: hasSubPage ? navItem.href : undefined }); } if (second === 'new') { crumbs.push({ label: 'Nouveau' }); } else if (second === 'edit') { const page = getPages().find(p => p.slug === `${first}:edit`); crumbs.push({ label: page?.breadcrumbLabel || page?.title || 'Modifier' }); } return crumbs; }; const breadcrumbs = buildBreadcrumbs(); const quickLinks = []; return (
{/* Left section — Mobile menu button + Logo / Desktop breadcrumb */}

{appName}

{/* Desktop breadcrumb — always rendered to keep user menu pinned right */}
{breadcrumbs.length > 0 && breadcrumbs.map((crumb, i) => ( {i > 0 && ( )} {crumb.icon ? ( ) : crumb.href ? ( ) : ( {crumb.label} )} ))}
{/* Right section — Quick links + Profile */}
{/* User Profile Menu */} {/* Name — desktop only */} {user?.name || 'User'}
{/* 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 AdminTop;