"use client"; import { Loader2, Send } from "lucide-react"; import { type KeyboardEvent, useState } from "react"; import { Button } from "@/components/ui/button"; import { Textarea } from "@/components/ui/textarea"; import { useChatTyping } from "@/lib/hooks/use-chat"; import { useSocket } from "@/lib/hooks/use-socket"; interface MessageInputProps { onSend: (content: string) => Promise; isSending: boolean; disabled?: boolean; chatId: string | null; } export function MessageInput({ onSend, isSending, disabled = false, chatId, }: MessageInputProps) { const [content, setContent] = useState(""); const { socket, isConnected } = useSocket(); const { handleTypingStart, handleTypingStop } = useChatTyping( socket, isConnected, chatId, ); const handleSubmit = async () => { if (!content.trim() || isSending || disabled) return; const messageContent = content.trim(); setContent(""); handleTypingStop(); await onSend(messageContent); }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleSubmit(); } }; const handleChange = (value: string) => { setContent(value); if (value.trim().length > 0) { handleTypingStart(); } else { handleTypingStop(); } }; return (