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 ContainerConsoleProps { remoteId: string; containerId: number; node: string; onClose?: () => void; onConnect?: () => void; onDisconnect?: () => void; } export function ContainerConsole({ containerId, node, onClose, onConnect, onDisconnect }: ContainerConsoleProps) { 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 container console'); setIsConnecting(false); } }; const handleDisconnect = () => { setConnected(false); setError(''); onDisconnect?.(); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Escape' && connected) { handleDisconnect(); } }; return ( Container Console - {node} / CT {containerId}
{connected ? ( ) : ( )} {onClose && ( )}
{!connected && !error && (

Click "Connect" to open container console

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