import React, { useMemo } from 'react'; import { Text } from '@mantine/core'; import { useTranslation } from 'react-i18next'; import { ToolRegistryEntry, getSubcategoryLabel, getSubcategoryColor, getSubcategoryIcon } from '../../data/toolsTaxonomy'; import { ToolId } from '../../types/toolId'; import { useToolSections } from '../../hooks/useToolSections'; import NoToolsFound from './shared/NoToolsFound'; import { useToolWorkflow } from '../../contexts/ToolWorkflowContext'; import StarRoundedIcon from '@mui/icons-material/StarRounded'; import ThumbUpRoundedIcon from '@mui/icons-material/ThumbUpRounded'; import Badge from '../shared/Badge'; import './ToolPanel.css'; import DetailedToolItem from './fullscreen/DetailedToolItem'; import CompactToolItem from './fullscreen/CompactToolItem'; import { useFavoriteToolItems } from '../../hooks/tools/useFavoriteToolItems'; interface FullscreenToolListProps { filteredTools: Array<{ item: [ToolId, ToolRegistryEntry]; matchedText?: string }>; searchQuery: string; showDescriptions: boolean; selectedToolKey: string | null; matchedTextMap: Map; onSelect: (id: ToolId) => void; } const FullscreenToolList = ({ filteredTools, searchQuery, showDescriptions, selectedToolKey, matchedTextMap: _matchedTextMap, onSelect, }: FullscreenToolListProps) => { const { t } = useTranslation(); const { toolRegistry, favoriteTools } = useToolWorkflow(); const { sections, searchGroups } = useToolSections(filteredTools, searchQuery); const tooltipPortalTarget = typeof document !== 'undefined' ? document.body : undefined; const favoriteToolItems = useFavoriteToolItems(favoriteTools, toolRegistry); const quickSection = useMemo(() => sections.find(section => section.key === 'quick'), [sections]); const recommendedItems = useMemo(() => { if (!quickSection) return [] as Array<{ id: string, tool: ToolRegistryEntry }>; const items: Array<{ id: string, tool: ToolRegistryEntry }> = []; quickSection.subcategories.forEach(sc => sc.tools.forEach(t => items.push(t))); return items; }, [quickSection]); // Show recommended/favorites section only when not searching const showRecentFavorites = searchQuery.trim().length === 0 && ((recommendedItems.length > 0) || favoriteToolItems.length > 0); const subcategoryGroups = useMemo(() => { if (searchQuery.trim().length > 0) { return searchGroups; } const allSection = sections.find(section => section.key === 'all'); return allSection ? allSection.subcategories : []; }, [searchGroups, sections, searchQuery]); if (subcategoryGroups.length === 0 && !showRecentFavorites) { return (
{t('toolPanel.fullscreen.noResults', 'Try adjusting your search or toggle descriptions to find what you need.')}
); } const containerClass = showDescriptions ? 'tool-panel__fullscreen-groups tool-panel__fullscreen-groups--detailed' : 'tool-panel__fullscreen-groups tool-panel__fullscreen-groups--compact'; // Helper function to render a tool item const renderToolItem = (id: ToolId, tool: ToolRegistryEntry) => { const isSelected = selectedToolKey === id; const handleClick = () => { if (!tool.component && !tool.link && id !== 'read' && id !== 'multiTool') return; if (tool.link) { window.open(tool.link, '_blank', 'noopener,noreferrer'); return; } onSelect(id as ToolId); }; if (showDescriptions) { return ( ); } return ( ); }; return (
{showRecentFavorites && ( <> {favoriteToolItems.length > 0 && (
{t('toolPanel.fullscreen.favorites', 'Favourites')}
{favoriteToolItems.length}
{showDescriptions ? (
{favoriteToolItems.map((item) => item && renderToolItem(item.id, item.tool))}
) : (
{favoriteToolItems.map((item) => item && renderToolItem(item.id, item.tool))}
)}
)} {recommendedItems.length > 0 && (
{t('toolPanel.fullscreen.recommended', 'Recommended')}
{recommendedItems.length}
{showDescriptions ? (
{recommendedItems.map((item: any) => renderToolItem(item.id, item.tool))}
) : (
{recommendedItems.map((item: any) => renderToolItem(item.id, item.tool))}
)}
)} )} {subcategoryGroups.map(({ subcategoryId, tools }) => { const categoryColor = getSubcategoryColor(subcategoryId); return (
{getSubcategoryIcon(subcategoryId)} {getSubcategoryLabel(t, subcategoryId)}
{tools.length}
{showDescriptions ? (
{tools.map(({ id, tool }) => renderToolItem(id as ToolId, tool))}
) : (
{tools.map(({ id, tool }) => renderToolItem(id as ToolId, tool))}
)}
); })}
); }; export default FullscreenToolList;