import { useEffect, useState } from 'react' import { Light as SyntaxHighlighter } from 'react-syntax-highlighter' import atomOneDark from 'react-syntax-highlighter/dist/esm/styles/hljs/atom-one-dark' import { X, Copy, Check, BookmarkPlus } from 'lucide-react' import { cn } from '@/lib/utils' const LANGUAGE_MAP: Record = { powershell: 'powershell', bash: 'bash', python: 'python', } const LANGUAGE_LABELS: Record = { powershell: 'PowerShell', bash: 'Bash', python: 'Python', } interface ScriptPreviewModalProps { script: string filename: string | null language: string onClose: () => void onSave: () => void } export function ScriptPreviewModal({ script, filename, language, onClose, onSave, }: ScriptPreviewModalProps) { const [copied, setCopied] = useState(false) const hlLanguage = LANGUAGE_MAP[language] || 'powershell' const lineCount = script.split('\n').length useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() } document.addEventListener('keydown', handleKeyDown) return () => document.removeEventListener('keydown', handleKeyDown) }, [onClose]) const handleCopy = async () => { try { await navigator.clipboard.writeText(script) setCopied(true) setTimeout(() => setCopied(false), 2000) } catch { // clipboard not available } } return (
{ if (e.target === e.currentTarget) onClose() }} >
{/* Header */}
{filename || 'script'} {LANGUAGE_LABELS[language] || language}
{/* Code body */}
{script}
{/* Footer */}
{lineCount} line{lineCount !== 1 ? 's' : ''}
) }