import { useState, useRef, useEffect } from 'react'; import { Brain, X } from 'lucide-react'; import { useTranslation } from 'react-i18next'; import { thinkingModes } from '../../constants/thinkingModes'; type ThinkingModeSelectorProps = { selectedMode: string; onModeChange: (modeId: string) => void; onClose?: () => void; className?: string; }; function ThinkingModeSelector({ selectedMode, onModeChange, onClose, className = '' }: ThinkingModeSelectorProps) { const { t } = useTranslation('chat'); // Mapping from mode ID to translation key const modeKeyMap: Record = { 'think-hard': 'thinkHard', 'think-harder': 'thinkHarder' }; // Create translated modes for display const translatedModes = thinkingModes.map(mode => { const modeKey = modeKeyMap[mode.id] || mode.id; return { ...mode, name: t(`thinkingMode.modes.${modeKey}.name`), description: t(`thinkingMode.modes.${modeKey}.description`), prefix: t(`thinkingMode.modes.${modeKey}.prefix`) }; }); const [isOpen, setIsOpen] = useState(false); const dropdownRef = useRef(null); useEffect(() => { const handleClickOutside = (event: MouseEvent) => { if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { setIsOpen(false); if (onClose) onClose(); } }; document.addEventListener('mousedown', handleClickOutside); return () => document.removeEventListener('mousedown', handleClickOutside); }, [onClose]); const currentMode = translatedModes.find(mode => mode.id === selectedMode) || translatedModes[0]; const IconComponent = currentMode.icon || Brain; return (
{isOpen && (

{t('thinkingMode.selector.title')}

{t('thinkingMode.selector.description')}

{translatedModes.map((mode) => { const ModeIcon = mode.icon; const isSelected = mode.id === selectedMode; return ( ); })}

Tip: {t('thinkingMode.selector.tip')}

)}
); } export default ThinkingModeSelector;