import { Message } from "@/types"; import { IconSend } from "@tabler/icons-react"; import { FC, KeyboardEvent, useEffect, useRef, useState } from "react"; interface Props { onSend: (message: Message) => void; } export const ChatInput: FC = ({ onSend }) => { const [content, setContent] = useState(); const textareaRef = useRef(null); const handleChange = (e: React.ChangeEvent) => { const value = e.target.value; if (value.length > 4000) { alert("Message limit is 4000 characters"); return; } setContent(value); }; const handleSend = () => { if (!content) { alert("Please enter a message"); return; } onSend({ role: "user", content }); setContent(""); }; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); handleSend(); } }; useEffect(() => { if (textareaRef && textareaRef.current) { textareaRef.current.style.height = "inherit"; textareaRef.current.style.height = `${textareaRef.current?.scrollHeight}px`; } }, [content]); return (