import { KeyboardEvent } from "react"; import { ActionIcon, Group, Textarea, Tooltip } from "@mantine/core"; import { IconPlayerStopFilled, IconSend } from "@tabler/icons-react"; import { useTranslation } from "react-i18next"; import { useAtom, useAtomValue } from "jotai"; import { aiChatDraftAtom } from "@/features/ai-chat/atoms/ai-chat-atom.ts"; import { workspaceAtom } from "@/features/user/atoms/current-user-atom"; import { MicButton } from "@/features/dictation/components/mic-button"; interface ChatInputProps { onSend: (text: string) => void; onStop: () => void; isStreaming: boolean; disabled?: boolean; } /** * Message composer. Enter sends, Shift+Enter inserts a newline. While the agent * is streaming, the send button becomes a Stop button (calls `stop()`); the * textarea stays usable so the user can draft the next turn. */ export default function ChatInput({ onSend, onStop, isStreaming, disabled, }: ChatInputProps) { const { t } = useTranslation(); const [value, setValue] = useAtom(aiChatDraftAtom); const workspace = useAtomValue(workspaceAtom); const isDictationEnabled = workspace?.settings?.ai?.dictation === true; const send = (): void => { const text = value.trim(); if (!text || isStreaming || disabled) return; onSend(text); setValue(""); }; const handleKeyDown = (e: KeyboardEvent): void => { if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); send(); } }; return (