import React from 'react'; import { useTranslation } from 'react-i18next'; import { CheckCircle, XCircle, AlertCircle } from '@/components/icons/LucideIcons'; interface PromptResultProps { result: { success: boolean; data?: any; error?: string; message?: string; }; onClose: () => void; } const PromptResult: React.FC = ({ result, onClose }) => { const { t } = useTranslation(); const renderContent = (content: any): React.ReactNode => { if (typeof content === 'string') { return (
{content}
); } if (typeof content === 'object' && content !== null) { // Handle the specific prompt data structure if (content.description || content.messages) { return (
{content.description && (

{t('prompt.description')}

{content.description}

)} {content.messages && (

{t('prompt.messages')}

{content.messages.map((message: any, index: number) => (
{message.role}:
{typeof message.content === 'string' ? (
                          {message.content}
                        
) : typeof message.content === 'object' && message.content.type === 'text' ? (
                          {message.content.text}
                        
) : (
                          {JSON.stringify(message.content, null, 2)}
                        
)}
))}
)}
); } // For other structured content, try to parse as JSON try { const parsed = typeof content === 'string' ? JSON.parse(content) : content; return (
{t('prompt.jsonResponse')}
{JSON.stringify(parsed, null, 2)}
); } catch { // If not valid JSON, show as string return (
{String(content)}
); } } return (
{String(content)}
); }; return (
{result.success ? ( ) : ( )}

{t('prompt.execution')} {result.success ? t('prompt.successful') : t('prompt.failed')}

{result.success ? (
{result.data ? (
{t('prompt.result')}
{renderContent(result.data)}
) : (
{t('prompt.noContent')}
)}
) : (
{t('prompt.error')}
                {result.error || result.message || t('prompt.unknownError')}
              
)}
); }; export default PromptResult;