'use client'; import * as React from 'react'; import { useRouter } from 'next/navigation'; const PLACEHOLDERS = [ "Ask your documents a question...", "Summarize the Q3 financial report...", "Extract action items from the meeting notes...", "Find clauses about termination...", ]; interface FloatingChatInputProps { /** * When provided, submitting calls this instead of navigating to /chat — * used by the homepage to run the conversation inline. Without it, the * input falls back to routing to the dedicated /chat page. */ onSubmitText?: (text: string) => void; disabled?: boolean; } export default function FloatingChatInput({ onSubmitText, disabled }: FloatingChatInputProps) { const router = useRouter(); const [val, setVal] = React.useState(''); const [phText, setPhText] = React.useState(''); const [phIndex, setPhIndex] = React.useState(0); const [isDeleting, setIsDeleting] = React.useState(false); React.useEffect(() => { const currentString = PLACEHOLDERS[phIndex]; let timeout: NodeJS.Timeout; if (isDeleting) { timeout = setTimeout(() => { setPhText(currentString.substring(0, phText.length - 1)); if (phText.length <= 1) { setIsDeleting(false); setPhIndex((prev) => (prev + 1) % PLACEHOLDERS.length); } }, 40); } else { timeout = setTimeout(() => { setPhText(currentString.substring(0, phText.length + 1)); if (phText.length === currentString.length) { timeout = setTimeout(() => { setIsDeleting(true); }, 2500); } }, 60); } return () => clearTimeout(timeout); }, [phText, isDeleting, phIndex]); const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); const text = val.trim(); if (!text) return; if (onSubmitText) { onSubmitText(text); setVal(''); } else { router.push(`/chat?q=${encodeURIComponent(text)}`); } }; const handleKeydown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSubmit(e as unknown as React.FormEvent); } }; return (
{/* Input Area */}