import { useState, useEffect, useRef } from 'react' import Editor from '@monaco-editor/react' import { motion } from 'framer-motion' import { FaPlay, FaSave, FaDownload, FaUpload, FaCopy, FaPaste, FaUndo, FaRedo, FaSearch, FaReplace, FaCog, FaExpand, FaCompress, FaTerminal, FaEye, FaCode, FaFile, FaFolder, FaPlus, FaMinus, FaTimes, FaCheck, FaSync, FaBug, FaRocket, FaShieldAlt, FaChartLine, FaDatabase, FaCloud, FaServer, FaGitAlt, FaLink, FaLock, FaUnlock, FaShare, FaStar, FaRegStar, FaBookmark, FaFlag, FaTag, FaTags, FaCalendar, FaClock, FaUser, FaUsers, FaComment, FaComments, FaHeart, FaRegHeart, FaThumbsUp, FaThumbsDown, FaEyeSlash, FaEdit, FaTrash, FaFileCode, FaFileAlt, FaFileArchive, FaFileImage, FaFileVideo, FaFileAudio, FaFilePdf, FaFileExcel, FaFileWord, FaFilePowerpoint, FaFileCsv, FaFileZip, FaFileMedical } from 'react-icons/fa' import toast from 'react-hot-toast' export default function CodeEditor({ language, theme }) { const [code, setCode] = useState(`// Welcome to AI Dev Studio function helloWorld() { console.log("Hello, World!"); return "Welcome to the future of coding!"; } helloWorld();`) const [currentLanguage, setCurrentLanguage] = useState('javascript') const [theme, setTheme] = useState('vs-dark') const [isFullscreen, setIsFullscreen] = useState(false) const [showTerminal, setShowTerminal] = useState(false) const [terminalOutput, setTerminalOutput] = useState([]) const [fontSize, setFontSize] = useState(14) const [wordWrap, setWordWrap] = useState(true) const [minimap, setMinimap] = useState(true) const [lineNumbers, setLineNumbers] = useState(true) const editorRef = useRef(null) const languages = [ { value: 'javascript', label: 'JavaScript' }, { value: 'typescript', label: 'TypeScript' }, { value: 'python', label: 'Python' }, { value: 'java', label: 'Java' }, { value: 'cpp', label: 'C++' }, { value: 'csharp', label: 'C#' }, { value: 'php', label: 'PHP' }, { value: 'ruby', label: 'Ruby' }, { value: 'go', label: 'Go' }, { value: 'rust', label: 'Rust' }, { value: 'sql', label: 'SQL' }, { value: 'html', label: 'HTML' }, { value: 'css', label: 'CSS' }, { value: 'json', label: 'JSON' }, { value: 'xml', label: 'XML' }, { value: 'yaml', label: 'YAML' }, { value: 'markdown', label: 'Markdown' }, { value: 'dockerfile', label: 'Dockerfile' }, { value: 'shell', label: 'Shell' }, { value: 'plaintext', label: 'Plain Text' } ] const handleRunCode = () => { const output = `> Running ${currentLanguage} code...\n> Code executed successfully!\n> Output: Hello, World!` setTerminalOutput(prev => [...prev, { type: 'success', message: output, timestamp: new Date() }]) setShowTerminal(true) toast.success('Code executed successfully!') } const handleSaveCode = () => { toast.success('Code saved successfully!') } const handleDownloadCode = () => { const blob = new Blob([code], { type: 'text/plain' }) const url = URL.createObjectURL(blob) const a = document.createElement('a') a.href = url a.download = `code.${getFileExtension()}` a.click() toast.success('Code downloaded!') } const getFileExtension = () => { const extensions = { javascript: 'js', typescript: 'ts', python: 'py', java: 'java', cpp: 'cpp', csharp: 'cs', php: 'php', ruby: 'rb', go: 'go', rust: 'rs', sql: 'sql', html: 'html', css: 'css', json: 'json', xml: 'xml', yaml: 'yaml', markdown: 'md', dockerfile: 'dockerfile', shell: 'sh', plaintext: 'txt' } return extensions[currentLanguage] || 'txt' } const formatCode = () => { if (editorRef.current) { editorRef.current.getAction('editor.action.formatDocument').run() toast.success('Code formatted!') } } const toggleFullscreen = () => { setIsFullscreen(!isFullscreen) } const clearTerminal = () => { setTerminalOutput([]) toast.success('Terminal cleared!') } return (