import React from 'react' import { CopyButton } from '@/components/ui/copy-button' import { useMobile } from '@/hooks/useMobile' import { cn } from '@/lib/utils' interface CodePreviewProps { fileName: string content: string } const INITIAL_CODE_LINES = 20 function extractFileFromPath(path: string): string { const parts = path.split('/') return parts[parts.length - 1] || path } function detectLanguage(fileName: string): string { const ext = fileName.split('.').pop()?.toLowerCase() const langMap: Record = { ts: 'typescript', tsx: 'typescript', js: 'javascript', jsx: 'javascript', py: 'python', rb: 'ruby', go: 'go', rs: 'rust', java: 'java', cs: 'csharp', cpp: 'cpp', c: 'c', h: 'c', json: 'json', yaml: 'yaml', yml: 'yaml', toml: 'toml', xml: 'xml', html: 'html', css: 'css', scss: 'scss', sass: 'sass', svg: 'svg', md: 'markdown', sh: 'bash', bash: 'bash', zsh: 'bash', fish: 'bash', sql: 'sql', php: 'php', swift: 'swift', kt: 'kotlin', dart: 'dart', } return langMap[ext || ''] || 'plaintext' } export function CodePreview({ fileName, content }: CodePreviewProps) { const isMobile = useMobile() const [showMore, setShowMore] = React.useState(false) const language = detectLanguage(fileName) const fileExtension = fileName.split('.').pop() || language const lines = content.split('\n') const totalLines = lines.length const isLargeFile = totalLines > INITIAL_CODE_LINES const displayedContent = isLargeFile && !showMore ? lines.slice(0, INITIAL_CODE_LINES).join('\n') : content return (
{extractFileFromPath(fileName)}
            
              {displayedContent}
            
          
{isLargeFile && !showMore && ( )} {isLargeFile && showMore && ( )}
) }