import React, { FC } from 'react'; import { useTranslation } from 'react-i18next'; import { Box, Typography, TextField, Button, Divider, Chip, FormControl, InputLabel, Select, MenuItem, Stack, Table, TableBody, TableCell, TableHead, TableRow, } from '@mui/material'; import { GenericModal } from '../ui/GenericModal'; interface AutoRobotData { id: string; name: string; category?: string; description?: string; access?: string; sample?: any[]; logo?: string; configOptions?: { parameters?: Array<{ id: string; label: string; type: 'dropdown' | 'search' | 'url' | 'limit' | 'username' | 'path-segment'; required?: boolean; placeholder?: string; queryParam: string; options?: Array<{ value: string; label: string; }>; }>; }; } interface AutoRobotDetailModalProps { open: boolean; onClose: () => void; robot: AutoRobotData | null; onUseRobot: (robot: AutoRobotData, config?: { parameters?: { [key: string]: string } }) => void; } export const AutoRobotDetailModal: FC = ({ open, onClose, robot, onUseRobot }) => { const { t } = useTranslation(); if (!robot) return null; const sampleData = robot.sample || []; const columnHeaders = sampleData.length > 0 ? Object.keys(sampleData[0]) : []; const needsConfiguration = robot.configOptions?.parameters && robot.configOptions.parameters.length > 0; const parameters = robot.configOptions?.parameters || []; const handleUseRobot = () => { onUseRobot(robot); }; return ( {robot.logo && ( )} {robot.name} {t('robot.description', 'Description')} {robot.description || t('recordingtable.no_description', 'No description available')} {needsConfiguration && ( {t('robot.config.configuration', 'Configuration')} {t('robot.config.info_message', 'The following fields will be required when you use this robot:')} {parameters.map((param) => { if (param.type === 'dropdown') { return ( {param.label}{param.required ? ' *' : ''} ); } if (param.type === 'search') { return ( ); } if (param.type === 'url') { return ( ); } if (param.type === 'limit') { return ( ); } if (param.type === 'username') { return ( ); } if (param.type === 'path-segment') { return ( ); } return null; })} )} {needsConfiguration && ( )} {sampleData.length > 0 && ( {t('robot.sample_output', 'Sample Output')} {columnHeaders.map((header, index) => ( {header} ))} {sampleData.map((row, rowIndex) => ( {columnHeaders.map((header, cellIndex) => ( {row[header] !== null ? (typeof row[header] === 'object' ? JSON.stringify(row[header]) : String(row[header])) : '-'} ))} ))}
)}
); }; export default AutoRobotDetailModal;