import React, { useMemo } from 'react'; import { Box, Stack, Text } from '@mantine/core'; import { type ToolRegistryEntry } from '../../data/toolRegistry'; import ToolButton from './toolPicker/ToolButton'; interface SearchResultsProps { filteredTools: [string, ToolRegistryEntry][]; onSelect: (id: string) => void; } const SearchResults: React.FC = ({ filteredTools, onSelect }) => { const groups = useMemo(() => { const subMap: Record> = {}; const seen = new Set(); filteredTools.forEach(([id, tool]) => { if (seen.has(id)) return; seen.add(id); const sub = tool?.subcategory || 'General'; if (!subMap[sub]) subMap[sub] = []; subMap[sub].push({ id, tool }); }); return Object.entries(subMap) .sort(([a], [b]) => a.localeCompare(b)) .map(([subcategory, tools]) => ({ subcategory, tools })); }, [filteredTools]); if (groups.length === 0) { return ( No tools found ); } return ( {groups.map(group => ( {group.subcategory} {group.tools.map(({ id, tool }) => ( ))} {/* bottom spacer within each group not strictly required, outer list can add a spacer if needed */} ))} {/* global spacer to allow scrolling past last row in search mode */}
); }; export default SearchResults;