import React, { useEffect, useState } from 'react'; import { UploadIcon } from './icons/UploadIcon'; import { TrendingUpIcon } from './icons/TrendingUpIcon'; import { BugIcon } from './icons/BugIcon'; import { ClockIcon } from './icons/ClockIcon'; import { LightbulbIcon } from './icons/LightbulbIcon'; import { ExclamationTriangleIcon } from './icons/StatusIcons'; import apiService, { AnalyticsResponse } from '../services/apiService'; // Agent performance is still static for now - would need separate API const agentPerformance = [ { name: 'Legal Agent', passRate: 85, avgIssues: 1.2, trend: 'up' }, { name: 'Brand Agent', passRate: 68, avgIssues: 2.5, trend: 'down' }, { name: 'Channel Best Practices Agent', passRate: 92, avgIssues: 0.8, trend: 'up' }, { name: 'Channel Tech Specs Agent', passRate: 71, avgIssues: 1.9, trend: 'stable' }, ]; const UpArrow = () => ; const DownArrow = () => ; const StableLine = () => ; const TrendIndicator: React.FC<{ trend: 'up' | 'down' | 'stable' }> = ({ trend }) => { if (trend === 'up') { return
Improving
; } if (trend === 'down') { return
Declining
; } return
Stable
; }; export const Analytics: React.FC = () => { const [analytics, setAnalytics] = useState(null); const [isLoading, setIsLoading] = useState(true); useEffect(() => { const loadAnalytics = async () => { try { const data = await apiService.getAnalytics(); setAnalytics(data); } catch (error) { console.error('Failed to load analytics:', error); } finally { setIsLoading(false); } }; loadAnalytics(); }, []); // Calculate stats from API data // Exclude errors from denominator since they weren't successfully reviewed const reviewedCount = analytics ? (analytics.passed || 0) + (analytics.failed || 0) + (analytics.legal_review || 0) : 0; const passRate = reviewedCount > 0 ? Math.round((analytics!.passed / reviewedCount) * 100) : 0; const stats = [ { name: 'Proofs Reviewed', value: analytics?.total_reviews?.toString() || '0', icon: UploadIcon }, { name: 'Pass Rate', value: `${passRate}%`, icon: TrendingUpIcon }, { name: 'Failed Reviews', value: analytics?.failed?.toString() || '0', icon: BugIcon }, { name: 'Analysis Errors', value: analytics?.errors?.toString() || '0', icon: ExclamationTriangleIcon }, { name: 'Legal Review Required', value: analytics?.legal_review?.toString() || '0', icon: ClockIcon }, ]; return (

Performance Analytics

Overall usage and performance statistics for the tool.

{/* Stats Cards */}
{stats.map((stat) => { const Icon = stat.icon; return (

{stat.name}

{stat.value}

); })}
{/* AI Performance Summary */}

AI Performance Summary

Key Insight (Last 7 Days):

A sharp decline in Best Practice adherence has been noted, primarily driven by proofs from the Barclays Q4 Social campaign. The Brand Guardian agent also shows a declining performance trend, suggesting a potential need for updated brand guideline training or proof review.

{/* Agent Performance Table */}

Agent Performance (Last 7 Days)

{agentPerformance.map((agent, index) => ( ))}
Agent Name Pass Rate Avg. Issues per Proof Performance Trend
{agent.name}
= 80 ? 'bg-success' : agent.passRate < 70 ? 'bg-error' : 'bg-warning'}`}> {agent.passRate}%
{agent.avgIssues}
); };