import { Check, CopyIcon, Edit, Loader2, X } from 'lucide-react' import { PropsWithChildren, useMemo, useState } from 'react' import { useDarkModeContext } from "../../../contexts/DarkModeContext" import { ApplyStatus, ToolArgs } from "../../../types/apply" import { MemoizedSyntaxHighlighterWrapper } from "./SyntaxHighlighterWrapper" export default function MarkdownEditFileBlock({ mode, applyStatus, onApply, language, path, startLine, endLine, children, }: PropsWithChildren<{ mode: string applyStatus: ApplyStatus onApply: (args: ToolArgs) => void language?: string path?: string startLine?: number endLine?: number }>) { const [copied, setCopied] = useState(false) const [applying, setApplying] = useState(false) const { isDarkMode } = useDarkModeContext() const wrapLines = useMemo(() => { return !language || ['markdown'].includes(language) }, [language]) const handleCopy = async () => { try { await navigator.clipboard.writeText(String(children)) setCopied(true) setTimeout(() => setCopied(false), 2000) } catch (err) { console.error('Failed to copy text: ', err) } } const handleApply = async () => { if (applyStatus !== ApplyStatus.Idle) { return } setApplying(true) onApply({ // @ts-ignore type: mode, filepath: path, content: String(children), startLine, endLine }) } return (
{path && (
{mode}: {path}
)}
{String(children)}
) }