1+ import React , { useState } from 'react' ;
2+ import { Button } from '@/components/ui/button' ;
3+ import {
4+ DropdownMenu ,
5+ DropdownMenuContent ,
6+ DropdownMenuItem ,
7+ DropdownMenuLabel ,
8+ DropdownMenuSeparator ,
9+ DropdownMenuTrigger
10+ } from '@/components/ui/dropdown-menu' ;
11+ import { Avatar , AvatarFallback } from '@/components/ui/avatar' ;
12+ import { Brain , User , Settings , LogOut , ChevronDown } from 'lucide-react' ;
13+ import { useAuth } from '@/contexts/AuthContext' ;
14+ import ProfileModal from './auth/ProfileModal' ;
15+
16+ interface NavigationProps {
17+ onBackToHome ?: ( ) => void ;
18+ showBackButton ?: boolean ;
19+ }
20+
21+ const Navigation : React . FC < NavigationProps > = ( { onBackToHome, showBackButton } ) => {
22+ const { user, logout, isAuthenticated } = useAuth ( ) ;
23+ const [ isProfileModalOpen , setIsProfileModalOpen ] = useState ( false ) ;
24+
25+ const handleLogout = ( ) => {
26+ logout ( ) ;
27+ if ( onBackToHome ) {
28+ onBackToHome ( ) ;
29+ }
30+ } ;
31+
32+ const getInitials = ( firstName ?: string , lastName ?: string ) => {
33+ if ( ! firstName || ! lastName ) return 'U' ;
34+ return `${ firstName . charAt ( 0 ) } ${ lastName . charAt ( 0 ) } ` . toUpperCase ( ) ;
35+ } ;
36+
37+ return (
38+ < nav className = "bg-white shadow-lg border-b" >
39+ < div className = "max-w-7xl mx-auto px-4 sm:px-6 lg:px-8" >
40+ < div className = "flex justify-between items-center h-16" >
41+ { /* Left side - Logo and back button */ }
42+ < div className = "flex items-center space-x-4" >
43+ < div className = "flex items-center space-x-3" >
44+ < div className = "w-8 h-8 bg-blue-500 rounded-full flex items-center justify-center" >
45+ < Brain className = "h-5 w-5 text-white" />
46+ </ div >
47+ < span className = "text-xl font-bold text-gray-900" > StudyMate</ span >
48+ </ div >
49+
50+ { showBackButton && onBackToHome && (
51+ < Button
52+ variant = "ghost"
53+ onClick = { onBackToHome }
54+ className = "text-gray-600 hover:text-gray-900"
55+ >
56+ ← Back to Home
57+ </ Button >
58+ ) }
59+ </ div >
60+
61+ { /* Right side - User menu or login button */ }
62+ < div className = "flex items-center space-x-4" >
63+ { isAuthenticated && user ? (
64+ < DropdownMenu >
65+ < DropdownMenuTrigger asChild >
66+ < Button
67+ variant = "ghost"
68+ className = "flex items-center space-x-2 hover:bg-gray-100"
69+ >
70+ < Avatar className = "h-8 w-8" >
71+ < AvatarFallback className = "bg-blue-500 text-white text-sm" >
72+ { getInitials ( user . firstName , user . lastName ) }
73+ </ AvatarFallback >
74+ </ Avatar >
75+ < span className = "hidden sm:block text-sm font-medium text-gray-700" >
76+ { user . firstName } { user . lastName }
77+ </ span >
78+ < ChevronDown className = "h-4 w-4 text-gray-500" />
79+ </ Button >
80+ </ DropdownMenuTrigger >
81+ < DropdownMenuContent align = "end" className = "w-56" >
82+ < DropdownMenuLabel >
83+ < div className = "flex flex-col space-y-1" >
84+ < p className = "text-sm font-medium text-gray-900" >
85+ { user . firstName } { user . lastName }
86+ </ p >
87+ < p className = "text-xs text-gray-500" >
88+ { user . email }
89+ </ p >
90+ </ div >
91+ </ DropdownMenuLabel >
92+ < DropdownMenuSeparator />
93+ < DropdownMenuItem
94+ onClick = { ( ) => setIsProfileModalOpen ( true ) }
95+ className = "cursor-pointer"
96+ >
97+ < User className = "mr-2 h-4 w-4" />
98+ < span > Profile</ span >
99+ </ DropdownMenuItem >
100+ < DropdownMenuItem
101+ onClick = { ( ) => setIsProfileModalOpen ( true ) }
102+ className = "cursor-pointer"
103+ >
104+ < Settings className = "mr-2 h-4 w-4" />
105+ < span > Settings</ span >
106+ </ DropdownMenuItem >
107+ < DropdownMenuSeparator />
108+ < DropdownMenuItem
109+ onClick = { handleLogout }
110+ className = "cursor-pointer text-red-600 hover:text-red-700 hover:bg-red-50"
111+ >
112+ < LogOut className = "mr-2 h-4 w-4" />
113+ < span > Log out</ span >
114+ </ DropdownMenuItem >
115+ </ DropdownMenuContent >
116+ </ DropdownMenu >
117+ ) : (
118+ < div className = "flex items-center space-x-2" >
119+ < Button
120+ variant = "ghost"
121+ onClick = { ( ) => window . location . href = '/login' }
122+ className = "text-gray-600 hover:text-gray-900"
123+ >
124+ Sign In
125+ </ Button >
126+ < Button
127+ onClick = { ( ) => window . location . href = '/register' }
128+ className = "bg-blue-500 hover:bg-blue-600 text-white"
129+ >
130+ Get Started
131+ </ Button >
132+ </ div >
133+ ) }
134+ </ div >
135+ </ div >
136+ </ div >
137+
138+ { /* Profile Modal */ }
139+ < ProfileModal
140+ isOpen = { isProfileModalOpen }
141+ onClose = { ( ) => setIsProfileModalOpen ( false ) }
142+ />
143+ </ nav >
144+ ) ;
145+ } ;
146+
147+ export default Navigation ;
0 commit comments