import { useEffect, useState } from 'react'; import { LogOut, Monitor, Smartphone } from 'lucide-react'; import { api } from '../../lib/api'; import { Session } from '../../lib/types'; // Rough device label from the user agent; good enough to tell one's own devices apart export function describeDevice(ua: string): { label: string; mobile: boolean } { if (!ua) return { label: 'Unbekanntes Gerät', mobile: false }; if (ua.startsWith('MindSift-')) return { label: 'MindSift-Client', mobile: false }; const mobile = /Android|iPhone|iPad|Mobile/i.test(ua); const browser = /Edg\//.test(ua) ? 'Edge' : /Firefox\//.test(ua) ? 'Firefox' : /Chrome\//.test(ua) ? 'Chrome' : /Safari\//.test(ua) ? 'Safari' : 'Browser'; const os = /Android/.test(ua) ? 'Android' : /iPhone|iPad/.test(ua) ? 'iOS' : /Windows/.test(ua) ? 'Windows' : /Mac OS X/.test(ua) ? 'macOS' : /Linux/.test(ua) ? 'Linux' : ''; return { label: os ? `${browser} auf ${os}` : browser, mobile }; } function formatLastUsed(iso: string): string { const d = new Date(iso); if (isNaN(d.getTime())) return ''; const minutes = Math.round((Date.now() - d.getTime()) / 60000); if (minutes < 10) return 'gerade aktiv'; return `zuletzt ${d.toLocaleString('de-DE', { dateStyle: 'medium', timeStyle: 'short' })}`; } export function SessionsPanel() { const [sessions, setSessions] = useState(null); const [error, setError] = useState(''); const [ending, setEnding] = useState(''); const load = async () => { try { const list = await api.listSessions(); setSessions([...list.filter((s) => s.current), ...list.filter((s) => !s.current)]); setError(''); } catch (err: any) { setError(err.message || 'Sitzungen konnten nicht geladen werden'); } }; useEffect(() => { void load(); }, []); const endSession = async (id: string) => { setEnding(id); try { await api.endSession(id); setSessions((prev) => (prev || []).filter((s) => s.id !== id)); } catch (err: any) { setError(err.message || 'Sitzung konnte nicht beendet werden'); } finally { setEnding(''); } }; if (error) return

{error}

; if (!sessions) return

Lade Sitzungen…

; return ( ); }