import React, { useState, useEffect } from 'react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { Menu, X, GraduationCap, BookOpen, Users, Award, Brain, Sun, Moon, Globe, LogIn, UserPlus, MessageCircle, Bell, LogOut, Wrench, LayoutDashboard, Settings } from 'lucide-react'; import { useTheme } from '../context/ThemeContext'; import { useAuth } from '../context/AuthContext'; import AskQuestionModal from './AskQuestionModal'; import { UserRole } from '../types'; import { socialLinkService, SocialLink } from '../services/socials'; import { Facebook, Twitter, Linkedin, Instagram, Youtube, Mail } from 'lucide-react'; interface LayoutProps { children: React.ReactNode; } const Layout: React.FC = ({ children }) => { const [isMobileMenuOpen, setIsMobileMenuOpen] = useState(false); const { isDark, toggleTheme } = useTheme(); const { user, isAuthenticated, logout, notifications } = useAuth(); const location = useLocation(); const navigate = useNavigate(); // Calcul dynamique des notifications non lues const unreadCount = notifications.filter(n => !n.isRead).length; const [socialLinks, setSocialLinks] = useState([]); useEffect(() => { const fetchSocials = async () => { try { const data = await socialLinkService.getSocialLinks(); setSocialLinks(data); } catch (error) { console.error("Failed to fetch social links", error); } }; fetchSocials(); }, []); const getSocialIcon = (iconName: string) => { switch (iconName) { case 'Facebook': return ; case 'Twitter': return ; case 'Linkedin': return ; case 'Instagram': return ; case 'Youtube': return ; case 'Mail': return ; default: return ; } }; const navItems = [ { path: '/', label: 'Accueil', icon: }, { path: '/questions', label: 'Questions', icon: }, { path: '/mentors', label: 'Mentors', icon: }, { path: '/opportunities', label: 'Opportunités', icon: }, { path: '/tools', label: 'Outils Pratiques', icon: }, { path: '/chat', label: 'Messages', icon: }, { path: '/ai-tutor', label: 'Tuteur IA', icon: }, ]; const isActive = (path: string) => location.pathname === path; const handleLogout = () => { logout(); setIsMobileMenuOpen(false); navigate('/login'); }; return (
{/* Header */}
{/* Logo */} EduLab Africa {/* Desktop Nav - Optimized spacing for xl screens (Tablet/Laptop uses hamburger) */} {/* User & Actions */}
{isAuthenticated && ( {unreadCount > 0 && ( {unreadCount > 9 ? '9+' : unreadCount} )} )} {isAuthenticated && user ? (
{user.points} pts
{user.name}
Profile
) : (
Se connecter S'inscrire
)}
{/* Mobile/Tablet Menu Button - Visible until XL */}
{/* Mobile/Tablet Navigation Drawer - Visible until XL */} { isMobileMenuOpen && (
{navItems.map((item) => ( setIsMobileMenuOpen(false)} className={`flex items-center space-x-3 px-4 py-3 rounded-xl ${isActive(item.path) ? 'bg-edu-secondary text-white' : 'text-gray-300 hover:bg-white/5' }`} > {item.icon} {item.label} ))} {/* Mentor Dashboard Link (Mobile) */} {user?.role === UserRole.MENTOR && ( setIsMobileMenuOpen(false)} className={`flex items-center space-x-3 px-4 py-3 rounded-xl border border-edu-accent ${isActive('/dashboard') ? 'bg-edu-accent text-edu-primary' : 'text-edu-accent hover:bg-white/5' }`} > Tableau de bord Mentor )} {/* Hide Auth Actions on Tablet (md) since they are visible in header */}
{!isAuthenticated ? ( <> setIsMobileMenuOpen(false)} className="flex items-center justify-center gap-2 w-full py-2 rounded-lg border border-white/20 text-white hover:bg-white/10" > Connexion setIsMobileMenuOpen(false)} className="flex items-center justify-center gap-2 w-full py-2 rounded-lg bg-edu-accent text-edu-primary font-bold hover:bg-white" > Inscription ) : ( <>
profile
{user?.name}
{user?.points} points
setIsMobileMenuOpen(false)} className="flex items-center gap-3 px-4 py-3 rounded-xl text-gray-300 hover:bg-white/5" > Mes Badges setIsMobileMenuOpen(false)} className="flex items-center gap-3 px-4 py-3 rounded-xl text-gray-300 hover:bg-white/5" > Paramètres )}
{isAuthenticated && ( setIsMobileMenuOpen(false)} className="flex items-center gap-2 text-gray-400">
{unreadCount > 0 && }
Notifications )}
Mode Sombre
) }
{/* Main Content */}
{children}
{/* Global Modals */} {/* Footer */}
); }; export default Layout;