import React, { useState } from 'react'; import { useTranslation } from 'react-i18next'; import { Button, Group, Text, ActionIcon, Menu, Box } from '@mantine/core'; import MoreVertIcon from '@mui/icons-material/MoreVert'; import EditIcon from '@mui/icons-material/Edit'; import DeleteIcon from '@mui/icons-material/Delete'; interface AutomationEntryProps { /** Optional title for the automation (usually for custom ones) */ title?: string; /** MUI Icon component for the badge */ badgeIcon?: React.ComponentType; /** Array of tool operation names in the workflow */ operations: string[]; /** Click handler */ onClick: () => void; /** Whether to keep the icon at normal color (for special cases like "Add New") */ keepIconColor?: boolean; /** Show menu for saved/suggested automations */ showMenu?: boolean; /** Edit handler */ onEdit?: () => void; /** Delete handler */ onDelete?: () => void; } export default function AutomationEntry({ title, badgeIcon: BadgeIcon, operations, onClick, keepIconColor = false, showMenu = false, onEdit, onDelete }: AutomationEntryProps) { const { t } = useTranslation(); const [isHovered, setIsHovered] = useState(false); const [isMenuOpen, setIsMenuOpen] = useState(false); // Keep item in hovered state if menu is open const shouldShowHovered = isHovered || isMenuOpen; const renderContent = () => { if (title) { // Custom automation with title return ( {BadgeIcon && ( )} {title} ); } else { // Suggested automation showing tool chain return ( {BadgeIcon && ( )} {operations.map((op, index) => ( {t(`${op}.title`, op)} {index < operations.length - 1 && ( )} ))} ); } }; return ( setIsHovered(true)} onMouseLeave={() => setIsHovered(false)} >
{renderContent()}
{showMenu && ( setIsMenuOpen(true)} onClose={() => setIsMenuOpen(false)} > e.stopPropagation()} style={{ opacity: shouldShowHovered ? 1 : 0, transform: shouldShowHovered ? 'scale(1)' : 'scale(0.8)', transition: 'opacity 0.3s ease, transform 0.3s ease', pointerEvents: shouldShowHovered ? 'auto' : 'none' }} > {onEdit && ( } onClick={(e) => { e.stopPropagation(); onEdit(); }} > {t('edit', 'Edit')} )} {onDelete && ( } onClick={(e) => { e.stopPropagation(); onDelete(); }} > {t('delete', 'Delete')} )} )}
); }