'use client'; import { useState, useEffect } from 'react'; import { useRouter } from 'next/navigation'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'; import { Bell, LogOut, Settings, User, Calendar } from 'lucide-react'; import { useToast } from '@/hooks/use-toast'; import { NotificationBell, AnnouncementsModal } from '@/components/notifications/announcements'; import { UserProfile } from '@/components/user/user-profile'; import { ModeToggle } from '@/components/ui/mode-toggle'; interface DashboardHeaderProps { user: { userId: string; email: string; role: 'user' | 'admin'; name?: string; surname?: string; }; } export function DashboardHeader({ user }: DashboardHeaderProps) { const router = useRouter(); const { toast } = useToast(); const [isLoggingOut, setIsLoggingOut] = useState(false); const [showAnnouncements, setShowAnnouncements] = useState(false); const [showUserProfile, setShowUserProfile] = useState(false); const [unreadCount, setUnreadCount] = useState(0); // Fetch unread announcements count on component mount useEffect(() => { fetchUnreadCount(); }, []); const fetchUnreadCount = async () => { try { const response = await fetch('/api/announcements'); if (response.ok) { const data = await response.json(); setUnreadCount(data.unreadCount || 0); } } catch (error) { console.error('Error fetching unread count:', error); } }; const handleLogout = async () => { setIsLoggingOut(true); try { await fetch('/api/auth/logout', { method: 'POST', }); toast({ title: 'Logged out successfully', description: 'See you next time!', }); router.push('/login'); router.refresh(); } catch (error) { toast({ title: 'Logout failed', description: 'Please try again', variant: 'destructive', }); } finally { setIsLoggingOut(false); } }; return (

TT Booking

{user.role === 'admin' && Admin}
setShowAnnouncements(true)} /> {user.role === 'admin' && ( )}
{/* Announcements Modal */} setShowAnnouncements(false)} unreadCount={unreadCount} onCountUpdate={setUnreadCount} /> {/* User Profile Modal */} User Profile
); }