"use client"; import { useEffect, useRef, useState, useMemo } from "react"; import Image from "next/image"; import { useChat } from "@/hooks/useChat"; import WelcomeSection from "./WelcomeSection"; import SuggestedQuestions from "./SuggestedQuestions"; import MessageBubble from "./MessageBubble"; import LoadingAnimation from "./LoadingAnimation"; import HexAvatar from "./HexAvatar"; import SettingsPanel from "./SettingsPanel"; export default function ChatInterface() { const { messages, isLoading, error, sendMessage, clearConversation, hasMessages, preferredModel, setPreferredModel, } = useChat(); const [input, setInput] = useState(""); const [settingsOpen, setSettingsOpen] = useState(false); const [slowHint, setSlowHint] = useState(false); const messagesEndRef = useRef(null); const inputRef = useRef(null); useEffect(() => { messagesEndRef.current?.scrollIntoView({ behavior: "smooth" }); }, [messages, isLoading]); // Free-tier backends can cold-start (~30-60s) after idling. If a reply is // slow, reassure the user instead of looking frozen. useEffect(() => { if (!isLoading) { setSlowHint(false); return; } const timer = setTimeout(() => setSlowHint(true), 8000); return () => clearTimeout(timer); }, [isLoading]); const handleSubmit = async () => { const text = input.trim(); if (!text || isLoading) return; setInput(""); await sendMessage(text); inputRef.current?.focus(); }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleSubmit(); } }; return (
{/* ── 3px gradient top accent bar ── */}
{/* ── Header — dark company-brand chrome ── */}
{/* Left — ULiT company identity */}
Users Love IT {/* Status button showing active model, remaining quota and reset timer */}
{/* Right — product badge + actions */}
NegOptim AI {hasMessages && ( <>
)} {/* Settings button */}
{/* ── Messages / Welcome area ── */}
{!hasMessages ? (
{ setInput(q); inputRef.current?.focus(); }} />
) : (
{messages.map((msg) => ( ))} {isLoading && (
{slowHint && (

Still working — the server may be waking from sleep, this can take up to a minute…

)}
)} {error && (
{error}
)}
)}
{/* ── Input bar ── */}