import React, { useState } from 'react'; import { Play, Trash2, Save, Copy, Check, ChevronDown } from 'lucide-react'; import { MonacoEditorWrapper } from './MonacoEditorWrapper'; interface CodePlaygroundProps { executeCodeAction: ( action: 'explain' | 'debug' | 'refactor' | 'generate-tests' | 'summarize', code: string, language: string, context?: string ) => Promise; isLoading: boolean; } const LANGUAGES = [ { id: 'python', name: 'Python' }, { id: 'typescript', name: 'TypeScript' }, { id: 'javascript', name: 'JavaScript' }, { id: 'rust', name: 'Rust' }, { id: 'go', name: 'Go' }, { id: 'cpp', name: 'C++' }, { id: 'html', name: 'HTML' }, { id: 'css', name: 'CSS' }, ]; const THEMES = [ { id: 'dracula', name: 'Dracula' }, { id: 'monokai', name: 'Monokai' }, { id: 'vs-dark', name: 'VS Dark' }, { id: 'github-dark', name: 'GitHub Dark' }, ]; export const CodePlayground: React.FC = ({ executeCodeAction, isLoading, }) => { const [code, setCode] = useState(`async def fetch_data(url: str): import aiohttp async with aiohttp.ClientSession() as session: async with session.get(url) as response: return await response.json() async def main(): urls = [ "https://api.github.com/users/octocat", "https://api.github.com/users/torvalds", "https://api.github.com/users/gaearon" ] results = await asyncio.gather(*(fetch_data(url) for url in urls)) for user in results: print(f"User: {user['login']} - {user['name']}") if __name__ == "__main__": import asyncio asyncio.run(main())`); const [language, setLanguage] = useState('python'); const [theme, setTheme] = useState('dracula'); const [output, setOutput] = useState(`octocat - The Octocat torvalds - Linus Torvalds gaearon - Dan Abramov Process finished with exit code 0`); const [activeConsoleTab, setActiveConsoleTab] = useState<'output' | 'console' | 'logs' | 'errors'>('output'); const [copied, setCopied] = useState(false); const [statusText, setStatusText] = useState('Running main.py ...\nSuccess'); const handleRun = async () => { if (!code.trim() || isLoading) return; setStatusText('Running main.py ...\nExecuting local environment...'); try { // Direct call to refactor/explain to act as Run execution const result = await executeCodeAction('explain', code, language); setOutput(result); setStatusText('Running main.py ...\nSuccess'); } catch (e: any) { setOutput(`Error during execution: ${e.message}`); setStatusText('Running main.py ...\nFailed'); } }; const handleClear = () => { setCode(''); }; const handleCopy = () => { navigator.clipboard.writeText(output); setCopied(true); setTimeout(() => setCopied(false), 2000); }; return (
{/* Playground Top Toolbar */}
{/* Left: Dropdown selectors */}
Language
Theme
{/* Right: Actions */}
{/* Main Split Layout: Editor & Outputs */}
{/* Left: Code Editor Container */}
{/* Tab Header bar */}
main.py
{/* Code Editor body */}
{/* Editor Status Bar Footer */}
Ln 1, Col 1 Spaces: 4 UTF-8 LF {language}
Execution time: {isLoading ? 'Running...' : '1.24s'} Memory: 45.6MB
{/* Right: Output Review Panel */}
{/* Output console tab headers */}
{(['output', 'console', 'logs', 'errors'] as const).map((tab) => ( ))}
{/* Console Text display */}
{activeConsoleTab === 'output' && (
                  {output}
                
{/* Diagnostics Status line indicator */}
Console output
                    {statusText}
                  
)} {activeConsoleTab === 'console' && (
# Interactive local interpreter session is active
)} {activeConsoleTab === 'logs' && (
[INFO] 172.18.0.3 - "GET /metrics HTTP/1.1" 200 OK
)} {activeConsoleTab === 'errors' && (
No compile execution errors reported.
)}
); };