'use client'; import { useState, useRef, useEffect } from 'react'; import type { Message } from '@/types'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; interface ChatInterfaceProps { messages: Message[]; onSendMessage: (message: string) => void; isGenerating: boolean; isAuthenticated?: boolean; } export default function ChatInterface({ messages, onSendMessage, isGenerating, isAuthenticated = false }: ChatInterfaceProps) { const [input, setInput] = useState(''); const messagesEndRef = useRef(null); const scrollToBottom = () => { messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }; useEffect(() => { scrollToBottom(); }, [messages]); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (input.trim() && !isGenerating) { onSendMessage(input); setInput(''); } }; return (
{/* Messages */}
{messages.length === 0 ? (
💬
{isAuthenticated ? ( <>

Start a conversation

Describe what you want to build and I'll generate the code

) : ( <>

🔒 Sign in to get started

Use Dev Login or sign in with Hugging Face

)}
) : ( messages.map((message, index) => (
{message.role === 'user' ? '👤' : '🤖'}
{message.role === 'assistant' ? ( {message.content} ) : (

{message.content}

)}
{message.timestamp && (
{new Date(message.timestamp).toLocaleTimeString()}
)}
)) )}
{/* Input */}
setInput(e.target.value)} placeholder={isAuthenticated ? "Message AnyCoder..." : "🔒 Please sign in first..."} disabled={isGenerating || !isAuthenticated} className="flex-1 px-4 py-3 bg-[#3a3a3c] text-[#e5e5e7] text-sm border border-[#48484a] rounded-xl focus:outline-none focus:ring-2 focus:ring-[#007aff] focus:border-transparent disabled:opacity-50 disabled:cursor-not-allowed placeholder-[#86868b] font-medium shadow-sm" />
); }