import { useState } from 'react'; import { InformationCircleIcon } from '@heroicons/react/24/solid'; import type { MachineInfo } from '../types/machine'; import { MachineStatus } from '../types/machine'; import { ConfirmDialog } from './ConfirmDialog'; import { shouldConfirmDisconnect, getStateVisualInfo } from '../utils/machineStateHelpers'; import { hasError, getErrorDetails } from '../utils/errorCodeHelpers'; interface MachineConnectionProps { isConnected: boolean; machineInfo: MachineInfo | null; machineStatus: MachineStatus; machineStatusName: string; machineError: number; isPolling: boolean; onConnect: () => void; onDisconnect: () => void; onRefresh: () => void; } export function MachineConnection({ isConnected, machineInfo, machineStatus, machineStatusName, machineError, isPolling, onConnect, onDisconnect, }: MachineConnectionProps) { const [showDisconnectConfirm, setShowDisconnectConfirm] = useState(false); const handleDisconnectClick = () => { if (shouldConfirmDisconnect(machineStatus)) { setShowDisconnectConfirm(true); } else { onDisconnect(); } }; const handleConfirmDisconnect = () => { setShowDisconnectConfirm(false); onDisconnect(); }; const stateVisual = getStateVisualInfo(machineStatus); const statusBadgeColors = { idle: 'bg-cyan-100 text-cyan-800 border-cyan-200', info: 'bg-cyan-100 text-cyan-800 border-cyan-200', active: 'bg-yellow-100 text-yellow-800 border-yellow-200', waiting: 'bg-yellow-100 text-yellow-800 border-yellow-200', warning: 'bg-yellow-100 text-yellow-800 border-yellow-200', complete: 'bg-green-100 text-green-800 border-green-200', success: 'bg-green-100 text-green-800 border-green-200', interrupted: 'bg-red-100 text-red-800 border-red-200', error: 'bg-red-100 text-red-800 border-red-200', danger: 'bg-red-100 text-red-800 border-red-200', }; // Only show error info when connected AND there's an actual error const errorInfo = (isConnected && hasError(machineError)) ? getErrorDetails(machineError) : null; return (