import React, { useState } from 'react'; import { createPortal } from 'react-dom'; import { useLanguage } from '../contexts/LanguageContext'; import { KnowledgeGroup } from '../types'; import { Check, X, Search, Database } from 'lucide-react'; interface GroupSelectionDrawerProps { isOpen: boolean; onClose: () => void; groups: KnowledgeGroup[]; selectedGroups: string[]; onSelectionChange: (groupIds: string[]) => void; } export const GroupSelectionDrawer: React.FC = ({ isOpen, onClose, groups, selectedGroups, onSelectionChange }) => { const { t } = useLanguage(); const [searchTerm, setSearchTerm] = useState(''); if (!isOpen) return null; const filteredGroups = groups.filter(g => g.name.toLowerCase().includes(searchTerm.toLowerCase()) ); const isAllSelected = selectedGroups.length === 0; const handleToggleGroup = (groupId: string) => { if (selectedGroups.includes(groupId)) { onSelectionChange(selectedGroups.filter(id => id !== groupId)); } else { onSelectionChange([...selectedGroups, groupId]); } }; const handleSelectAll = () => { onSelectionChange([]); }; return createPortal(

{t('selectKnowledgeGroups')}

{/* Search Box */}
setSearchTerm(e.target.value)} className="w-full pl-9 pr-4 py-2 text-sm border border-gray-200 rounded-lg focus:outline-none focus:border-blue-500 focus:ring-1 focus:ring-blue-500 bg-gray-50" />
{!searchTerm && (
{isAllSelected && }
{t('all')}
)} {filteredGroups.map((group) => { const isSelected = selectedGroups.includes(group.id); return (
handleToggleGroup(group.id)} className={`flex items-center px-4 py-3 cursor-pointer hover:bg-slate-50 rounded-xl transition-all ${isSelected ? 'bg-blue-50/50 outline outline-1 outline-blue-200' : 'border border-transparent' }`} >
{isSelected && }
{group.name}
{group.fileCount} 个文件
); })} {filteredGroups.length === 0 && (
{searchTerm ? t('noGroupsFound') : t('noGroups')}
)}
, document.body ); };