import { useState } from "react"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { Download, Copy, Play, X } from "lucide-react"; import { useToast } from "@/hooks/use-toast"; type CodePanelProps = { fileName: string; language: string; code: string; onClose?: () => void; onRun?: () => void; }; export function CodePanel({ fileName, language, code, onClose, onRun }: CodePanelProps) { const { toast } = useToast(); const [copied, setCopied] = useState(false); const handleCopy = async () => { await navigator.clipboard.writeText(code); setCopied(true); toast({ title: "Copied!", description: "Code copied to clipboard", }); setTimeout(() => setCopied(false), 2000); }; const handleDownload = () => { const blob = new Blob([code], { type: "text/plain" }); const url = URL.createObjectURL(blob); const a = document.createElement("a"); a.href = url; a.download = fileName; a.click(); URL.revokeObjectURL(url); toast({ title: "Downloaded!", description: `${fileName} has been downloaded`, }); }; return (
{code}