import React, { useState, useRef, useEffect } from 'react'; import { Search, Bell, ChevronDown, LogOut, User, Settings, Shield } from 'lucide-react'; export default function Header({ profile }) { const [isProfileOpen, setIsProfileOpen] = useState(false); const dropdownRef = useRef(null); // Close dropdown on click outside useEffect(() => { function handleClickOutside(event) { if (dropdownRef.current && !dropdownRef.current.contains(event.target)) { setIsProfileOpen(false); } } document.addEventListener("mousedown", handleClickOutside); return () => document.removeEventListener("mousedown", handleClickOutside); }, []); const handleLogout = async () => { const csrfToken = document.querySelector('meta[name="csrf-token"]')?.getAttribute('content'); try { const response = await fetch('/logout', { method: 'POST', headers: { 'X-CSRF-TOKEN': csrfToken } }); if (response.ok || response.status === 419) { window.location.href = '/'; } } catch (error) { console.error('Logout failed:', error); // Fallback for SPA window.location.href = '/'; } }; return (
{/* Logo */}

GymPro

{/* Search Bar */}
{/* User Actions */}
setIsProfileOpen(!isProfileOpen)} className="flex items-center gap-3 pl-6 border-l border-gray-100 cursor-pointer group select-none" >
{profile?.user?.name || 'Loading...'} {profile?.role ? profile.role.charAt(0).toUpperCase() + profile.role.slice(1) : 'User'}
{profile?.user?.name?.split(' ').map(n => n[0]).join('').toUpperCase() || 'U'}
{/* Profile Dropdown */} {isProfileOpen && (

Active Account

{profile?.user?.email || '...'}

)}
); }