'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

) : ( <>

Sign in to get started

Use Dev Login or sign in with Hugging Face

)}
) : ( messages.map((message, index) => (
{message.timestamp && (
{new Date(message.timestamp).toLocaleTimeString()}
)}
)) )}
{/* Input */}
setInput(e.target.value)} placeholder={isAuthenticated ? "Message AnyCoder..." : "Sign in first..."} disabled={isGenerating || !isAuthenticated} className="flex-1 px-4 py-2.5 bg-[#2d2d2f] text-[#f5f5f7] text-sm border border-[#424245]/50 rounded-full focus:outline-none focus:border-[#424245] disabled:opacity-40 disabled:cursor-not-allowed placeholder-[#86868b]" />
); }