import React, { useState } from 'react';
import ReactMarkdown from 'react-markdown';
import remarkMath from 'remark-math';
import rehypeKatex from 'rehype-katex';
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
import { vscDarkPlus } from 'react-syntax-highlighter/dist/esm/styles/prism';
import { Copy, Check, Terminal } from 'lucide-react';
const CodeBlock = ({ node, inline, className, children, ...props }: any) => {
const [copied, setCopied] = useState(false);
const match = /language-(\w+)/.exec(className || '');
const language = match ? match[1] : '';
// Inline code (e.g. `const x = 1`)
if (inline) {
return (
{children}
);
}
const codeString = String(children).replace(/\n$/, '');
const handleCopy = () => {
navigator.clipboard.writeText(codeString);
setCopied(true);
setTimeout(() => setCopied(false), 2000);
};
return (