import React, { useState, useEffect, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { Modal, Title, Button, Group, Stack, Text, Alert } from '@mantine/core'; import SettingsIcon from '@mui/icons-material/Settings'; import CheckIcon from '@mui/icons-material/Check'; import CloseIcon from '@mui/icons-material/Close'; import WarningIcon from '@mui/icons-material/Warning'; import { ToolRegistry } from '../../../data/toolsTaxonomy'; import { getAvailableToExtensions } from '../../../utils/convertUtils'; interface ToolConfigurationModalProps { opened: boolean; tool: { id: string; operation: string; name: string; parameters?: any; }; onSave: (parameters: any) => void; onCancel: () => void; toolRegistry: ToolRegistry; } export default function ToolConfigurationModal({ opened, tool, onSave, onCancel, toolRegistry }: ToolConfigurationModalProps) { const { t } = useTranslation(); const [parameters, setParameters] = useState({}); const [isValid, setIsValid] = useState(true); // Get tool info from registry const toolInfo = toolRegistry[tool.operation]; const SettingsComponent = toolInfo?.settingsComponent; // Initialize parameters from tool (which should contain defaults from registry) useEffect(() => { if (tool.parameters) { setParameters(tool.parameters); } else { // Fallback to empty parameters if none provided setParameters({}); } }, [tool.parameters, tool.operation]); // Render the settings component const renderToolSettings = () => { if (!SettingsComponent) { return ( } color="orange"> {t('automate.config.noSettings', 'This tool does not have configurable settings.')} ); } // Special handling for ConvertSettings which needs additional props if (tool.operation === 'convert') { return ( { setParameters((prev: any) => ({ ...prev, [key]: value })); }} getAvailableToExtensions={getAvailableToExtensions} selectedFiles={[]} disabled={false} /> ); } return ( { setParameters((prev: any) => ({ ...prev, [key]: value })); }} disabled={false} /> ); }; const handleSave = () => { if (isValid) { onSave(parameters); } }; return ( {t('automate.config.title', 'Configure {{toolName}}', { toolName: tool.name })} } size="lg" centered > {t('automate.config.description', 'Configure the settings for this tool. These settings will be applied when the automation runs.')}
{renderToolSettings()}
); }