import React, { useState, useEffect, useRef } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/index'; import { Button } from '@/components/ui/index'; import { Alert, AlertDescription, AlertTitle } from '@/components/ui/index'; import { Terminal } from 'lucide-react'; interface VMConsoleProps { remoteId: string; vmId: number; node: string; onClose?: () => void; onConnect?: () => void; onDisconnect?: () => void; } export function VMConsole({ vmId, node, onClose, onConnect, onDisconnect }: VMConsoleProps) { const [connected, setConnected] = useState(false); const [error, setError] = useState(''); const [isConnecting, setIsConnecting] = useState(false); const terminalRef = useRef(null); useEffect(() => { if (connected && terminalRef.current) { terminalRef.current.focus(); } }, [connected]); const handleConnect = async () => { setIsConnecting(true); setError(''); try { await new Promise((resolve) => { setTimeout(() => { setConnected(true); setIsConnecting(false); onConnect?.(); resolve(true); }, 1000); }); } catch { setError('Failed to connect to VM console'); setIsConnecting(false); } }; const handleDisconnect = () => { setConnected(false); setError(''); onDisconnect?.(); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Escape' && connected) { handleDisconnect(); } }; return ( VM Console - {node} / VM {vmId}
{connected ? ( ) : ( )} {onClose && ( )}
{!connected && !error && (

Click "Connect" to open VM console

)} {error && ( Connection Error {error} )} {connected && (
VM Console - Press ESC to disconnect
Proxmox VE VM Console
Connected to {node} / VM {vmId}
----------------------------------------
_
)}
); }