import { useEffect } from 'react' import { Link } from 'react-router-dom' import { X, GitBranch, Terminal, Layers, BarChart3, ShieldCheck, CheckCircle2, Package, ChevronRight, } from 'lucide-react' import { cn } from '@/lib/utils' import type { PublicFlowDetail, PublicScriptDetail } from '@/types' type TemplateDetailModalProps = | { type: 'flow' template: PublicFlowDetail onClose: () => void } | { type: 'script' template: PublicScriptDetail onClose: () => void } const complexityColors: Record = { basic: 'text-emerald-400', intermediate: 'text-amber-400', advanced: 'text-rose-500', } export function TemplateDetailModal(props: TemplateDetailModalProps) { const { type, template, onClose } = props // Close on Escape useEffect(() => { function handleKey(e: KeyboardEvent) { if (e.key === 'Escape') onClose() } document.addEventListener('keydown', handleKey) return () => document.removeEventListener('keydown', handleKey) }, [onClose]) // Prevent body scroll while modal is open useEffect(() => { document.body.style.overflow = 'hidden' return () => { document.body.style.overflow = '' } }, []) return (
{/* Backdrop */}
{/* Modal */}
e.stopPropagation()} > {/* Header */}
{type === 'flow' ? ( ) : ( )}

{template.name} {type === 'script' && (template as PublicScriptDetail).is_verified && ( )}

{type === 'flow' ? 'Flow Template' : 'Script Template'}

{/* Body */}
{template.description && (

{template.description}

)} {/* Metadata */}
{type === 'flow' && ( <> } /> {(template as PublicFlowDetail).success_rate !== null && ( } valueClassName={ (template as PublicFlowDetail).success_rate! >= 80 ? 'text-emerald-400' : (template as PublicFlowDetail).success_rate! >= 50 ? 'text-amber-400' : 'text-rose-500' } /> )} )} {type === 'script' && ( <> {(template as PublicScriptDetail).complexity && ( )} {(template as PublicScriptDetail).requires_elevation && ( } /> )} )}
{/* Tags */} {template.tags.length > 0 && (

Tags

{template.tags.map((tag) => ( {tag} ))}
)} {/* Flow preview structure */} {type === 'flow' && (template as PublicFlowDetail).preview_structure && (

Flow Preview

)} {/* Script parameters */} {type === 'script' && (template as PublicScriptDetail).parameters.length > 0 && (

Parameters

{(template as PublicScriptDetail).parameters.map((param) => (
{param.name} {param.description} {param.type}
))}
)} {/* Script modules */} {type === 'script' && (template as PublicScriptDetail).requires_modules.length > 0 && (

Required Modules

{(template as PublicScriptDetail).requires_modules.map((mod) => ( {mod} ))}
)}
{/* Footer */}
Sign Up to Use This
) } function MetaStat({ label, value, icon, valueClassName, }: { label: string value: string icon?: React.ReactNode valueClassName?: string }) { return (
{label}
{icon} {value}
) } /** * Renders a simplified nested list from the preview_structure object. * Expected shape: { name: string, children?: Array<...> } */ function PreviewTree({ structure }: { structure: Record }) { const name = (structure.name as string) || (structure.title as string) || 'Root' const children = (structure.children as Array>) || [] return (
{name}
{children.length > 0 && (
{children.slice(0, 8).map((child, i) => ( ))} {children.length > 8 && ( +{children.length - 8} more steps... )}
)}
) }