import React, { useState } from "react"; import { Button } from "@/components/ui/button"; import { Check, Copy } from "lucide-react"; import { useToast } from "@/hooks/use-toast"; export default function CodeBlock({ code, language = "python" }: { code: string; language?: string }) { const [hasCopied, setHasCopied] = useState(false); const { toast } = useToast(); const copyToClipboard = () => { if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") { navigator.clipboard.writeText(code).then(() => { setHasCopied(true); toast({ title: "Copied to clipboard!", description: "The training script is ready to be used.", }); setTimeout(() => { setHasCopied(false); }, 2000); }).catch(err => { toast({ variant: "destructive", title: "Failed to copy", description: "Could not copy to clipboard. Please try again.", }); }); } else { toast({ variant: "destructive", title: "Clipboard API not available", description: "Please use a secure (HTTPS) environment to enable clipboard access.", }); } }; return (
{code}