import { useState } from 'react' import { useNavigate } from 'react-router-dom' import { useAuth } from '@/contexts/AuthContext' import { useTheme } from '@/contexts/ThemeContext' import { useProfile } from '@/contexts/ProfileProvider' import { useDateTimePreference } from '@/contexts/DateTimePreferenceContext' import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' import { Label } from '@/components/ui/label' import { Separator } from '@/components/ui/separator' import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, } from '@/components/ui/dropdown-menu' import { Dialog, DialogContent } from '@/components/ui/dialog' import { AlertDialog, AlertDialogContent, } from '@/components/ui/alert-dialog' import { User, Settings, LogOut, Sun, Moon, Monitor, Loader2, Check, Clock } from 'lucide-react' import { AVATAR_COLORS } from '@/data/profile.data' // ─── Theme Option ───────────────────────────────────────────────────────────── function ThemeOption({ value, label, icon: Icon, active, onClick }) { return ( ) } // ─── Timezone Option ────────────────────────────────────────────────────────── function TimezoneOption({ value, label, description, active, onClick }) { return ( ) } // ─── Settings Dialog ────────────────────────────────────────────────────────── function SettingsDialog({ open, onClose }) { const { theme, setTheme } = useTheme() const { timezone, setTimezone } = useDateTimePreference() const [tab, setTab] = useState('appearance') const TABS = [ { id: 'appearance', label: 'Appearance', icon: Sun }, { id: 'datetime', label: 'Date & Time', icon: Clock }, ] return (
{/* ── Sidebar ── */}
Settings
{/* ── Content ── */}
{/* Appearance */} {tab === 'appearance' && (

Appearance

Choose how the interface looks for you.

)} {/* Date & Time */} {tab === 'datetime' && (

Date & Time

Choose how dates and times are displayed across the platform. Your locale format is taken from your browser's language setting.

Preview

Date: {new Date().toLocaleDateString(navigator.language, { month: 'short', day: 'numeric', year: 'numeric', ...(timezone === 'UTC' ? { timeZone: 'UTC' } : {}) })}

Date & Time: {new Date().toLocaleString(navigator.language, { month: 'short', day: 'numeric', year: 'numeric', hour: 'numeric', minute: '2-digit', ...(timezone === 'UTC' ? { timeZone: 'UTC' } : {}) })}

{timezone === 'UTC' &&

All times shown in UTC

}
)}
) } // ─── Sign Out Overlay ───────────────────────────────────────────────────────── function SignOutOverlay({ open }) { return (

Signing out...

) } // ─── Main UserMenu ──────────────────────────────────────────────────────────── export default function UserMenu() { const { user, logout } = useAuth() const { avatarUrl } = useProfile() const navigate = useNavigate() const [settingsOpen, setSettingsOpen] = useState(false) const [signingOut, setSigningOut] = useState(false) // Build initials from personal_info or fallback to acc_type first char const given = user?.personal_info?.name?.given_name ?? '' const last = user?.personal_info?.name?.last_name ?? '' const initials = given && last ? (given[0] + last[0]).toUpperCase() : (user?.email?.[0] ?? 'U').toUpperCase() const fullName = given && last ? `${given} ${last}` : user?.email ?? 'User' const shortName = (given || user?.email) ?? 'User' const avatarColor = AVATAR_COLORS[user?.acc_type] ?? 'bg-muted text-muted-foreground' const handleLogout = async () => { setSigningOut(true) await logout() navigate('/login', { replace: true }) } return ( <> {initials} {/* User info */}

{shortName}

{user?.email ?? '—'}

navigate('my-profile')}> Profile setSettingsOpen(true)}> Settings Sign out
{/* Settings dialog */} setSettingsOpen(false)} /> {/* Sign out overlay */} ) }