import { useEffect, useRef } from 'react' import { Bot, User, Loader2 } from 'lucide-react' import { cn } from '@/lib/utils' import { MarkdownContent } from '@/components/ui/MarkdownContent' import { ScriptCodeBlock } from './ScriptCodeBlock' import type { ScriptBuilderMessage } from '@/types' interface ScriptBuilderChatProps { messages: ScriptBuilderMessage[] language: string onViewScript: (script: string, filename: string | null) => void onSaveScript: () => void isLoading: boolean } export function ScriptBuilderChat({ messages, language, onViewScript, onSaveScript, isLoading, }: ScriptBuilderChatProps) { const bottomRef = useRef(null) useEffect(() => { bottomRef.current?.scrollIntoView({ behavior: 'smooth' }) }, [messages.length, isLoading]) if (messages.length === 0 && !isLoading) { return (

Script Builder

Describe the script you need and AI will generate it for you. You can iterate on the script, preview it, and save it to your library.

) } return (
{messages.map((msg, idx) => (
{msg.role === 'assistant' && (
)}
{msg.role === 'assistant' ? ( <> {msg.script && ( onViewScript(msg.script!, msg.script_filename ?? null)} onSave={onSaveScript} /> )} ) : (

{msg.content}

)}
{msg.role === 'user' && (
)}
))} {isLoading && (
Generating script...
)}
) }