import { useEffect, useRef, useState } from 'react'; import { Link, useLocation, useNavigate } from 'react-router-dom'; import { motion, AnimatePresence } from 'framer-motion'; import { useAuth } from '@/hooks/useAuth'; import { APP_NAME } from '@/utils/constants'; import { BrandLogo } from '@/components/BrandLogo'; import { ClipboardList, LogOut, Moon, NotebookPen, Sun, User } from 'lucide-react'; import { MOTION_DURATION, MOTION_EASE, fastTransition } from '@/lib/motion'; import { useTheme } from '@/hooks/useTheme'; import { cn } from '@/lib/utils'; /** * Minimal top shell: product mark + profile menu (Course Status, Logout). * Replaces the former bottom navigation. */ export function AppHeader() { const { isAuthenticated, signOut, isGuest, user } = useAuth(); const { toggleTheme, isDark } = useTheme(); const navigate = useNavigate(); const location = useLocation(); const [menuOpen, setMenuOpen] = useState(false); const [showLogoutConfirm, setShowLogoutConfirm] = useState(false); const menuRef = useRef(null); const isAuthPage = location.pathname === '/login' || location.pathname === '/signup'; const usernameLabel = isGuest ? 'مهمان' : user?.email?.trim() || 'کاربر'; useEffect(() => { setMenuOpen(false); }, [location.pathname]); useEffect(() => { if (!menuOpen) return; const onPointerDown = (event: MouseEvent) => { if (menuRef.current && !menuRef.current.contains(event.target as Node)) { setMenuOpen(false); } }; const onKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') setMenuOpen(false); }; document.addEventListener('mousedown', onPointerDown); document.addEventListener('keydown', onKeyDown); return () => { document.removeEventListener('mousedown', onPointerDown); document.removeEventListener('keydown', onKeyDown); }; }, [menuOpen]); const handleSignOut = async () => { await signOut(); setShowLogoutConfirm(false); setMenuOpen(false); navigate('/login', { replace: true }); }; if (isAuthPage || (!isAuthenticated && !isGuest)) { return null; } return ( <>
setMenuOpen((open) => !open)} whileHover={{ scale: 1.04 }} whileTap={{ scale: 0.96 }} transition={fastTransition} className={cn( 'inline-flex h-9 w-9 items-center justify-center rounded-full border transition-colors duration-200', 'border-slate-200 bg-white text-sky-700 shadow-sm', 'hover:border-sky-300 hover:bg-sky-50 hover:text-sky-800', 'dark:border-slate-600/60 dark:bg-slate-800 dark:text-sky-300 dark:shadow-none', 'dark:hover:border-slate-500 dark:hover:bg-slate-700 dark:hover:text-sky-200', menuOpen && 'border-sky-400 ring-2 ring-sky-400/25 dark:border-sky-500 dark:ring-sky-500/20' )} aria-label="منوی پروفایل" aria-expanded={menuOpen} aria-haspopup="menu" > {menuOpen && (

نام کاربری

{usernameLabel}

setMenuOpen(false)} > وضعیت دوره setMenuOpen(false)} > تکالیف من {user?.role === 'admin' ? ( setMenuOpen(false)} > پنل ادمین ) : null}
)}
{showLogoutConfirm && (

خروج از حساب کاربری

آیا مطمئن هستید که می‌خواهید خارج شوید؟

)} ); }