import { ArrowRight, Loader2, Reply, SmilePlus, X } from "lucide-react"; import { Popover, PopoverContent, PopoverTrigger } from "../ui/popover"; import { useRef, useState } from "react"; import EmojiPicker from "./EmojiPicker"; import type { MessageList } from "../../../src/api/types/models"; // Message input component const MessageInput = ({ onSend, replyToMessage, onCancelReply, messageText, setMessageText, isSendingMessage, setReplyToMessage, }: { onSend: (text: string) => void; replyToMessage: MessageList | undefined; onCancelReply: () => void; inputRef: React.RefObject; messageText: string; setMessageText: React.Dispatch>; isSendingMessage: boolean; setReplyToMessage: (message: MessageList | undefined) => void; }) => { const [caretPosition, setCaretPosition] = useState(null); // Track current textarea height const handleSend = () => { if (!messageText.trim() || isSendingMessage) return; onSend(messageText.trim()); }; // Handle emoji selection const handleSelectEmoji = (selectedEmoji: string) => { if (textareaRef.current) { // Get current cursor position const cursorPosition = caretPosition !== null ? caretPosition : textareaRef.current.selectionStart; // Insert emoji at cursor position const newText = messageText.substring(0, cursorPosition) + selectedEmoji + messageText.substring(cursorPosition); setMessageText(newText); // After state update, set cursor position after the inserted emoji setTimeout(() => { if (textareaRef.current) { const newPosition = cursorPosition + selectedEmoji.length; textareaRef.current.focus(); textareaRef.current.setSelectionRange(newPosition, newPosition); } }, 0); } else { // Fallback if ref not available setMessageText((prev) => prev + selectedEmoji); } }; // Store caret position on selection change const handleTextareaSelect = () => { if (textareaRef.current) { setCaretPosition(textareaRef.current.selectionStart); } }; // Auto-growing textarea ref const textareaRef = useRef(null); // Handle text change and update height const handleTextChange = (e: React.ChangeEvent) => { setMessageText(e.target.value); }; return ( <> {/* Reply indicator */} {replyToMessage && (

در پاسخ به:

{replyToMessage.content}

)}
{replyToMessage && (
{replyToMessage.content}
)}