"use client"; import { useState, useRef, useEffect } from "react"; import styles from "./MessageInput.module.css"; import useSpeechRecognition from "@/hooks/useSpeechRecognition"; export default function MessageInput({ onSend, disabled = false }) { const [text, setText] = useState(""); const textareaRef = useRef(null); const handleSend = () => { const trimmed = text.trim(); if (!trimmed || disabled) return; onSend(trimmed); setText(""); // Reset textarea height if (textareaRef.current) { textareaRef.current.style.height = "auto"; } }; const handleKeyDown = (e) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleSend(); } }; const handleInput = (e) => { setText(e.target.value); // Auto-grow textarea const el = e.target; el.style.height = "auto"; el.style.height = Math.min(el.scrollHeight, 120) + "px"; }; const { startListening, isListening } = useSpeechRecognition((transcript) => { setText((prev) => { const newText = prev ? prev + " " + transcript : transcript; if (textareaRef.current) { textareaRef.current.style.height = "auto"; textareaRef.current.style.height = Math.min(textareaRef.current.scrollHeight, 120) + "px"; } return newText; }); }); return (