// AI Failure Detection modal (#1546) — opened from the printer card's AI badge. // Shows the live classification for this printer and the detection service's // last error, without leaving the Printers page (mirrors the HMS error modal). import { useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useNavigate } from 'react-router-dom'; import { X, ScanEye, AlertCircle, Settings } from 'lucide-react'; interface AiDetectionModalProps { printerName: string; detection?: { class: string; frame_count: number; score: number }; // null = no error, or the viewer lacks settings:read (the backend withholds // error strings from non-settings users because they can embed config URLs) lastError: string | null; onClose: () => void; } export function AiDetectionModal({ printerName, detection, lastError, onClose }: AiDetectionModalProps) { const { t } = useTranslation(); const navigate = useNavigate(); useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; window.addEventListener('keydown', handleKeyDown); return () => window.removeEventListener('keydown', handleKeyDown); }, [onClose]); const cls = detection ? (detection.class === 'failure' || detection.class === 'warning' ? detection.class : 'safe') : 'idle'; const statusColor = cls === 'failure' ? 'text-status-error' : cls === 'warning' ? 'text-status-warning' : cls === 'safe' ? 'text-status-ok' : 'text-bambu-gray'; return (
{t('printers.aiDetection.idleHint')}
)}{lastError}