import { useState, useRef, useEffect } from "react"; import { ChatMessage, type Message } from "./ChatMessage"; import { ChatInput } from "./ChatInput"; import { CodePanel } from "./CodePanel"; import { FileUploadZone } from "./FileUploadZone"; import { TypingIndicator } from "./TypingIndicator"; import { Button } from "@/components/ui/button"; import { SidebarTrigger } from "@/components/ui/sidebar"; import { Moon, Sun, Code2 } from "lucide-react"; import { useTheme } from "./ThemeProvider"; import { ScrollArea } from "@/components/ui/scroll-area"; type ChatInterfaceProps = { buddyName: string; onSettingsClick: () => void; }; export function ChatInterface({ buddyName, onSettingsClick }: ChatInterfaceProps) { const { theme, toggleTheme } = useTheme(); const [messages, setMessages] = useState([]); const [isTyping, setIsTyping] = useState(false); const [showFileUpload, setShowFileUpload] = useState(false); const [showCodePanel, setShowCodePanel] = useState(false); const scrollRef = useRef(null); useEffect(() => { if (scrollRef.current) { scrollRef.current.scrollTop = scrollRef.current.scrollHeight; } }, [messages, isTyping]); const handleSendMessage = (content: string) => { const userMessage: Message = { id: Date.now().toString(), role: "user", content, timestamp: new Date(), }; setMessages((prev) => [...prev, userMessage]); setIsTyping(true); setTimeout(() => { const aiMessage: Message = { id: (Date.now() + 1).toString(), role: "assistant", content: `I'm ${buddyName}, powered by Dolphin-Mistral! I'd be happy to help you with that. This is a demo response showing how I would assist you with coding, debugging, or any other development tasks.`, timestamp: new Date(), }; setMessages((prev) => [...prev, aiMessage]); setIsTyping(false); }, 2000); }; const handleFileUpload = () => { setShowFileUpload(!showFileUpload); }; const handleFilesSelected = (files: File[]) => { console.log('Files selected:', files); setShowFileUpload(false); setShowCodePanel(true); }; return (

{buddyName}

Online • Dolphin-Mistral 3.0

{showFileUpload ? (
setShowFileUpload(false)} />
) : ( <>
{messages.length === 0 ? (

Welcome to AI Buddy

Start a conversation with your AI coding companion. I can help you with:

  • • Code analysis and debugging
  • • Multi-language support
  • • File uploads and code modification
  • • Best practices and optimization
) : (
{messages.map((message) => ( ))} {isTyping && (
{buddyName}
)}
)}
)}
{showCodePanel && (
setShowCodePanel(false)} onRun={() => console.log('Run code')} />
)}
); }