import { useId } from 'react'; import { Loader2, ArrowUp } from 'lucide-react'; import { cn } from '@/lib/utils'; import { KeywordBadge } from '@/components/KeywordBadge'; import { CardThumb } from '@/components/CardThumb'; import { useMentions } from '@/components/useMentions'; interface QueryInputProps { value: string; onChange: (v: string) => void; onSubmit: () => void; loading: boolean; placeholder?: string; } export function QueryInput({ value, onChange, onSubmit, loading, placeholder }: QueryInputProps) { const trimmed = value.trim(); const isValid = trimmed.length >= 3 && trimmed.length <= 1000; const label = placeholder ?? 'Ask the judge a rules question'; const { active, items, index, inputRef, containerRef, activeItemRef, handleInputChange, handleKeyDown: onMentionKeyDown, select, } = useMentions({ value, onChange }); // Stable ids for the ARIA combobox wiring (input ↔ listbox ↔ active option). const inputId = useId(); const listboxId = useId(); const optionId = (i: number) => `${listboxId}-opt-${i}`; function handleKeyDown(e: React.KeyboardEvent) { if (onMentionKeyDown(e)) return; if (e.key === 'Enter') { // Single-line field: always suppress the form's implicit submit so // Shift+Enter never sends. Plain Enter submits explicitly below. e.preventDefault(); if (!e.shiftKey && !loading && isValid) onSubmit(); } } function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!loading && isValid) onSubmit(); } return (
{active && ( )}
); }