"use client" import { useState, useRef, useEffect } from "react" import { Button } from "@/components/ui/button" import { Card } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { ScrollArea } from "@/components/ui/scroll-area" import { Send, User, Copy, RotateCcw, ThumbsUp, ThumbsDown, Paperclip, Mic, Square } from "lucide-react" import { NovaLogo } from "@/components/ui/nova-logo" type Message = { id: string content: string role: "user" | "assistant" timestamp: Date isStreaming?: boolean } export function AIChatInterfaceBlock() { const [input, setInput] = useState("") const [isGenerating, setIsGenerating] = useState(false) const [messages, setMessages] = useState([ { id: "1", content: "Hello! I'm Nova, your AI assistant. I can help you with a wide variety of tasks like writing, analysis, math, coding, creative projects, and answering questions. What would you like to work on today?", role: "assistant", timestamp: new Date(Date.now() - 1000 * 60 * 5), }, { id: "2", content: "Can you help me understand the key principles of responsive web design and provide some practical examples?", role: "user", timestamp: new Date(Date.now() - 1000 * 60 * 4), }, { id: "3", content: `I'd be happy to explain responsive web design! Here are the key principles: ## Core Principles **1. Fluid Grid Layouts** Use relative units like percentages instead of fixed pixels for layout containers. **2. Flexible Images and Media** Ensure images scale appropriately with their containers using \`max-width: 100%\`. **3. Media Queries** Apply different styles based on device characteristics like screen width. ## Practical Examples ### CSS Grid Example \`\`\`css .container { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1rem; } \`\`\` ### Responsive Typography \`\`\`css h1 { font-size: clamp(1.5rem, 4vw, 3rem); } \`\`\` ### Mobile-First Media Query \`\`\`css /* Mobile styles first */ .sidebar { display: none; } /* Tablet and up */ @media (min-width: 768px) { .sidebar { display: block; } } \`\`\` These techniques ensure your website looks great on all devices, from mobile phones to desktop computers.`, role: "assistant", timestamp: new Date(Date.now() - 1000 * 60 * 3), }, ]) const scrollAreaRef = useRef(null) const handleSend = async () => { if (!input.trim() || isGenerating) return const userMessage: Message = { id: Date.now().toString(), content: input, role: "user", timestamp: new Date(), } setMessages((prev) => [...prev, userMessage]) setInput("") setIsGenerating(true) // Simulate AI response with streaming effect setTimeout(() => { const aiMessage: Message = { id: (Date.now() + 1).toString(), content: getAIResponse(input), role: "assistant", timestamp: new Date(), isStreaming: true, } setMessages((prev) => [...prev, aiMessage]) // Stop streaming after delay setTimeout(() => { setMessages((prev) => prev.map((msg) => (msg.id === aiMessage.id ? { ...msg, isStreaming: false } : msg))) setIsGenerating(false) }, 2000) }, 500) } const getAIResponse = (userInput: string): string => { const input = userInput.toLowerCase() if (input.includes("hello") || input.includes("hi")) { return "Hello! How can I assist you today? I'm Nova, your AI companion, and I'm here to help with any questions or tasks you might have." } else if (input.includes("code") || input.includes("programming")) { return `I'd be happy to help with coding! Here's a simple example: \`\`\`javascript function greetUser(name) { return \`Hello, \${name}! Welcome to our application.\`; } console.log(greetUser("Developer")); \`\`\` What specific programming topic would you like to explore?` } else { return "That's an interesting question! I'd be happy to help you explore this topic further. Could you provide a bit more context about what specifically you'd like to know?" } } const copyToClipboard = (text: string) => { navigator.clipboard.writeText(text) } const formatTime = (date: Date) => { return date.toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" }) } useEffect(() => { if (scrollAreaRef.current) { scrollAreaRef.current.scrollTop = scrollAreaRef.current.scrollHeight } }, [messages]) return ( {/* Header */}

Nova

AI Assistant

{/* Messages */}
{messages.map((message, index) => (
{/* Avatar */}
{message.role === "assistant" ? (
) : (
)}
{/* Content */}
{message.role === "assistant" ? "Nova" : "You"} {formatTime(message.timestamp)} {message.isStreaming && (
Generating...
)}
{message.content}
{/* Message Actions */} {message.role === "assistant" && !message.isStreaming && (
)}
))} {/* Generating indicator */} {isGenerating && (
Nova
Thinking...
)}
{/* Input */}
{ e.preventDefault() handleSend() }} className="relative" >
setInput(e.target.value)} placeholder="Message Nova..." className="flex-1 border-0 bg-transparent focus-visible:ring-0 focus-visible:ring-offset-0 resize-none min-h-[20px] max-h-[120px]" disabled={isGenerating} />
{isGenerating ? ( ) : ( )}

Nova can make mistakes. Please use with discretion.

) }