import { useState } from 'react' import { usePlatform } from '@/hooks/usePlatform' import { useShikiHighlighter } from '@/lib/shiki' function safeCopyToClipboard(text: string): Promise { if (navigator.clipboard?.writeText) { return navigator.clipboard.writeText(text) } return Promise.reject(new Error('Clipboard API not available')) } function CopyIcon(props: { className?: string }) { return ( ) } function CheckIcon(props: { className?: string }) { return ( ) } export function CodeBlock(props: { code: string language?: string showCopyButton?: boolean }) { const { haptic } = usePlatform() const showCopyButton = props.showCopyButton ?? true const [copied, setCopied] = useState(false) const highlighted = useShikiHighlighter(props.code, props.language) const handleCopy = async () => { try { await safeCopyToClipboard(props.code) haptic.notification('success') setCopied(true) setTimeout(() => setCopied(false), 1500) } catch { haptic.notification('error') } } return (
{showCopyButton ? ( ) : null}
                    {highlighted ?? props.code}
                
) }