'use client'; import React, { useState, useRef, useEffect } from 'react'; import { Mic, MicOff, Send, Sparkles, Layers, Zap, ArrowUp, Globe, Radio, Volume2 } from 'lucide-react'; import { sounds } from '@/src/lib/soundEffects'; interface ChatInputBarProps { onSendMessage: (text: string) => void; isProcessing: boolean; isRecording: boolean; audioLevel?: number; liveTranscript?: string; onToggleRecording: () => void; onStartRecording?: () => void; onStopRecording?: () => void; selectedLanguage: string; } export function ChatInputBar({ onSendMessage, isProcessing, isRecording, audioLevel = 0, liveTranscript = '', onToggleRecording, onStartRecording, onStopRecording, selectedLanguage, }: ChatInputBarProps) { const [text, setText] = useState(''); const textareaRef = useRef(null); const wasRecordingRef = useRef(false); // Sync live real-time speech recognition transcript into the searchbox useEffect(() => { if (isRecording && liveTranscript) { setText(liveTranscript); } }, [isRecording, liveTranscript]); // Auto-resize textarea useEffect(() => { if (textareaRef.current) { textareaRef.current.style.height = 'auto'; textareaRef.current.style.height = `${Math.min(120, textareaRef.current.scrollHeight)}px`; } }, [text]); // Instantly clear searchbox when recording stops useEffect(() => { if (wasRecordingRef.current && !isRecording) { setText(''); if (textareaRef.current) { textareaRef.current.style.height = 'auto'; } } wasRecordingRef.current = isRecording; }, [isRecording]); const handleSubmit = (e?: React.FormEvent) => { if (e) e.preventDefault(); if (!text.trim() || isProcessing) return; sounds.playBlip(); onSendMessage(text.trim()); setText(''); if (textareaRef.current) { textareaRef.current.style.height = 'auto'; } }; const handleKeyDown = (e: React.KeyboardEvent) => { if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); handleSubmit(); } }; const handleMicClick = () => { sounds.playBlip(); onToggleRecording(); }; return (
{/* Main Floating Input Capsule */}
{/* Live Recording Ambient Audio Indicator */} {isRecording && (
Listening to your voice...
{/* Dynamic Gradient Acoustic Visualizer Wave */}
{[25, 60, 95, 45, 80, 100, 70, 40, 85, 30].map((baseHeight, idx) => (
))}
Auto-sends on pause
)} {/* Textarea Input (Always visible, streams speech in real time) */}