import React from "react"; import { Button } from "@mantine/core"; import { Tooltip } from "../../shared/Tooltip"; import { ToolRegistryEntry } from "../../../data/toolsTaxonomy"; import { useToolNavigation } from "../../../hooks/useToolNavigation"; import { handleUnlessSpecialClick } from "../../../utils/clickHandlers"; import FitText from "../../shared/FitText"; interface ToolButtonProps { id: string; tool: ToolRegistryEntry; isSelected: boolean; onSelect: (id: string) => void; rounded?: boolean; disableNavigation?: boolean; } const ToolButton: React.FC = ({ id, tool, isSelected, onSelect, disableNavigation = false }) => { const isUnavailable = !tool.component && !tool.link; const { getToolNavigation } = useToolNavigation(); const handleClick = (id: string) => { if (isUnavailable) return; if (tool.link) { // Open external link in new tab window.open(tool.link, '_blank', 'noopener,noreferrer'); return; } // Normal tool selection onSelect(id); }; // Get navigation props for URL support (only if navigation is not disabled) const navProps = !isUnavailable && !tool.link && !disableNavigation ? getToolNavigation(id, tool) : null; const tooltipContent = isUnavailable ? (Coming soon: {tool.description}) : tool.description; const buttonContent = ( <>
{tool.icon}
); const handleExternalClick = (e: React.MouseEvent) => { handleUnlessSpecialClick(e, () => handleClick(id)); }; const buttonElement = navProps ? ( // For internal tools with URLs, render Button as an anchor for proper link behavior ) : tool.link && !isUnavailable ? ( // For external links, render Button as an anchor with proper href ) : ( // For unavailable tools, use regular button ); return ( {buttonElement} ); }; export default ToolButton;