import React, { useState, useRef } from 'react'; import { Send, Search, Loader2 } from 'lucide-react'; import { useStore } from '../store/useStore.js'; export default function MentionInput({ onSend, sending }) { const { models, webSearchEnabled, toggleWebSearch } = useStore(); const [value, setValue] = useState(''); const [mentionState, setMentionState] = useState(null); const textareaRef = useRef(null); const filteredModels = mentionState ? models.filter(m => m.tag.toLowerCase().startsWith(mentionState.query.toLowerCase())) : []; const handleChange = (e) => { const text = e.target.value; setValue(text); const pos = e.target.selectionStart; const before = text.slice(0, pos); const match = before.match(/@(\w*)$/); if (match) { setMentionState({ start: match.index, query: match[1] }); } else { setMentionState(null); } }; const insertMention = (tag) => { if (!mentionState) return; const before = value.slice(0, mentionState.start); const after = value.slice(mentionState.start + 1 + mentionState.query.length); const newVal = `${before}@${tag} ${after}`; setValue(newVal); setMentionState(null); textareaRef.current?.focus(); }; const handleKeyDown = (e) => { if (mentionState && filteredModels.length > 0 && e.key === 'Enter') { e.preventDefault(); insertMention(filteredModels[0].tag); return; } if (mentionState && e.key === 'Escape') { setMentionState(null); return; } if (e.key === 'Enter' && !e.shiftKey) { e.preventDefault(); submit(); } }; const submit = () => { const text = value.trim(); if (!text || sending) return; setValue(''); setMentionState(null); onSend(text); }; const activeTags = models.filter(m => new RegExp(`@${m.tag}\\b`, 'i').test(value)); return (