import { useState, useEffect } from 'react'; import { Loader2, ExternalLink, RefreshCw, Terminal } from 'lucide-react'; interface SandboxPreviewProps { sandboxId: string; port: number; type: 'vite' | 'nextjs' | 'console'; output?: string; isLoading?: boolean; } export default function SandboxPreview({ sandboxId, port, type, output, isLoading = false }: SandboxPreviewProps) { const [previewUrl, setPreviewUrl] = useState(''); const [showConsole, setShowConsole] = useState(false); const [iframeKey, setIframeKey] = useState(0); useEffect(() => { if (sandboxId && type !== 'console') { // In production, this would be the actual E2B sandbox URL // Format: https://{sandboxId}-{port}.e2b.dev setPreviewUrl(`https://${sandboxId}-${port}.e2b.dev`); } }, [sandboxId, port, type]); const handleRefresh = () => { setIframeKey(prev => prev + 1); }; if (type === 'console') { return (
{output || 'No output yet...'}
); } return (
{/* Preview Controls */}
{type === 'vite' ? '⚡ Vite' : '▲ Next.js'} Preview {previewUrl}
{/* Main Preview */}
{isLoading && (

{type === 'vite' ? 'Starting Vite dev server...' : 'Starting Next.js dev server...'}

)}