import React, { useState, useEffect } from 'react'; interface LearningData { learningSystem: { enabled: boolean; learningActive?: boolean; activeDecisions?: number; message?: string; recommendation?: string; report?: { summary?: { totalDecisions?: number; successRate?: number; systemConfidence?: number; }; insights?: { thresholds?: any; confidenceLevel?: number; }; recommendations?: string[]; }; }; visibility?: { decisionTrackingActive?: boolean; learningDatabaseConnected?: boolean; aiEnhancementsActive?: boolean; lastUpdateTime?: string; }; automationStatus?: any; } const EnhancedAILearningPanel = () => { const [learningData, setLearningData] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchLearningStatus = async () => { try { setLoading(true); // Get both learning status and automation status const [learningResponse, statusResponse] = await Promise.all([ fetch('/api/automation/learning-status'), fetch('/api/automation/status') ]); const learningData = await learningResponse.json(); const statusData = await statusResponse.json(); setLearningData({ ...learningData, automationStatus: statusData }); setError(null); } catch (err) { console.error('Error fetching learning status:', err); setError(err instanceof Error ? err.message : 'Unknown error'); } finally { setLoading(false); } }; useEffect(() => { fetchLearningStatus(); // Refresh every 30 seconds const interval = setInterval(fetchLearningStatus, 30000); return () => clearInterval(interval); }, []); if (loading) { return (

🧠 AI Learning System

Loading learning status...
); } if (error) { return (

🧠 AI Learning System

Error: {error}
); } if (!learningData) { return null; } const { learningSystem, visibility } = learningData; const renderLearningStatus = () => { if (!learningSystem.enabled) { return (
Learning System Not Active
{learningSystem.message || 'The AI learning system is not currently integrated with the automation.'}
{learningSystem.recommendation && (
💡 {learningSystem.recommendation}
)}
• Decision recording: Not active
• Learning database: Not connected
• AI enhancements: Not applied
); } return (
AI Learning Active
{learningSystem.report && (
Total Decisions
{learningSystem.report.summary?.totalDecisions || 0}
Success Rate
{learningSystem.report.summary?.successRate || 0}%
Confidence
{learningSystem.report.summary?.systemConfidence || 0}%
)}
🔍 Learning Visibility
Decision Tracking
Database Connected
AI Enhancements
0 ? 'bg-blue-500' : 'bg-gray-500'}`}>
0 ? 'text-blue-400' : 'text-gray-400'}> Active Decisions ({learningSystem.activeDecisions || 0})
{learningSystem.report?.insights && (
🎯 Learning Insights
{learningSystem.report.insights.thresholds && (
Current Thresholds: {JSON.stringify(learningSystem.report.insights.thresholds)}
)} {learningSystem.report.insights.confidenceLevel && (
Confidence Level: {learningSystem.report.insights.confidenceLevel}%
)}
)} {learningSystem.report?.recommendations && learningSystem.report.recommendations.length > 0 && (
💡 AI Recommendations
{learningSystem.report.recommendations.map((rec: string, index: number) => (
• {rec}
))}
)}
); }; return (

🧠 AI Learning System

{renderLearningStatus()} {visibility?.lastUpdateTime && (
Last updated: {new Date(visibility.lastUpdateTime).toLocaleTimeString()}
)}
); }; export default EnhancedAILearningPanel;