import { useState } from 'react' import { Light as SyntaxHighlighter } from 'react-syntax-highlighter' import powershell from 'react-syntax-highlighter/dist/esm/languages/hljs/powershell' import bash from 'react-syntax-highlighter/dist/esm/languages/hljs/bash' import python from 'react-syntax-highlighter/dist/esm/languages/hljs/python' import atomOneDark from 'react-syntax-highlighter/dist/esm/styles/hljs/atom-one-dark' import { Eye, Copy, Check, BookmarkPlus } from 'lucide-react' SyntaxHighlighter.registerLanguage('powershell', powershell) SyntaxHighlighter.registerLanguage('bash', bash) SyntaxHighlighter.registerLanguage('python', python) const LANGUAGE_MAP: Record = { powershell: 'powershell', bash: 'bash', python: 'python', } interface ScriptCodeBlockProps { script: string filename: string | null lineCount: number | null language: string onViewFull: () => void onSave: () => void } export function ScriptCodeBlock({ script, filename, lineCount, language, onViewFull, onSave, }: ScriptCodeBlockProps) { const [copied, setCopied] = useState(false) const lines = script.split('\n') const previewLines = lines.slice(0, 5).join('\n') const remainingLines = lines.length - 5 const hlLanguage = LANGUAGE_MAP[language] || 'powershell' const handleCopy = async (e: React.MouseEvent) => { e.stopPropagation() try { await navigator.clipboard.writeText(script) setCopied(true) setTimeout(() => setCopied(false), 2000) } catch { // clipboard not available } } return (
{/* Header */}
{filename || 'script'} {lineCount != null && ( {lineCount} lines )}
{/* Code preview — clickable */} {/* Action buttons */}
) }