import { useEffect, useRef, useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button } from '@/components/ui/button'; import { cn } from '@/lib/utils/cn'; import { type LogEntry, useLogStore } from '@/stores/logStore'; function formatTime(timestamp: number): string { const d = new Date(timestamp); return d.toLocaleTimeString(undefined, { hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, }); } function LogLine({ entry }: { entry: LogEntry }) { return (
{formatTime(entry.timestamp)} {entry.line}
); } export function LogsPage() { const { t } = useTranslation(); const entries = useLogStore((s) => s.entries); const clear = useLogStore((s) => s.clear); const containerRef = useRef(null); const [autoScroll, setAutoScroll] = useState(true); // Auto-scroll to bottom when new entries arrive useEffect(() => { if (autoScroll && containerRef.current) { containerRef.current.scrollTop = containerRef.current.scrollHeight; } }, [entries.length, autoScroll]); // Detect manual scroll to disable auto-scroll const handleScroll = () => { const el = containerRef.current; if (!el) return; const atBottom = el.scrollHeight - el.scrollTop - el.clientHeight < 40; setAutoScroll(atBottom); }; return (

{t('settings.logs.title')}

{t('settings.logs.lineCount', { count: entries.length })}

{!autoScroll && ( )}
{entries.length === 0 ? (

{t('settings.logs.empty')}

{!import.meta.env?.PROD &&

{t('settings.logs.devHint')}

}
) : ( entries.map((entry) => ) )}
); }