+ {/* Time Range Selector */}
+
+
Analytics Dashboard
+
+ {(['today', 'week', 'month', 'quarter'] as const).map((range) => (
+
+ ))}
+
+
+
+ {/* Quick Stats */}
+
+ {[
+ {
+ title: 'Total Appointments',
+ value: quickStats.totalInteractions?.value || '0',
+ change: quickStats.totalInteractions?.change || '0%',
+ isPositive: quickStats.totalInteractions?.isPositive || false,
+ icon: (
+
+ ),
+ color: '#FFC72C'
+ },
+ {
+ title: 'Response Time',
+ value: `${quickStats.avgResponseTime?.value || '0'}${quickStats.avgResponseTime?.unit || 'min'}`,
+ change: quickStats.avgResponseTime?.change || '0%',
+ isPositive: quickStats.avgResponseTime?.isPositive || false,
+ icon: (
+
+ ),
+ color: '#008060'
+ },
+ {
+ title: 'Completion Rate',
+ value: `${quickStats.satisfactionRate?.value || '0'}${quickStats.satisfactionRate?.unit || '%'}`,
+ change: quickStats.satisfactionRate?.change || '0%',
+ isPositive: quickStats.satisfactionRate?.isPositive || false,
+ icon: (
+
+ ),
+ color: '#FF5722'
+ },
+ {
+ title: 'Resolution Rate',
+ value: `${quickStats.resolutionRate?.value || '0'}${quickStats.resolutionRate?.unit || '%'}`,
+ change: quickStats.resolutionRate?.change || '0%',
+ isPositive: quickStats.resolutionRate?.isPositive || false,
+ icon: (
+
+ ),
+ color: '#8D153A'
+ }
+ ].map((stat, index) => (
+
+
+
+ {stat.icon}
+
+
+ {stat.isPositive ? '↗' : '↘'} {stat.change}
+
+
+
{stat.value}
+
{stat.title}
+
+ ))}
+
+
+ {/* Performance Chart */}
+
+
+
+ {hasChartData ? (
+ chartData.slice(0, 7).map((item, index: number) => {
+ const appointments = item.interactions || 0;
+ const completion = item.satisfaction || 0;
+ const appointmentHeight = appointments > 0 ? Math.max(15, (appointments / 25) * 100) : 0;
+ const completionHeight = completion > 0 ? Math.max(20, (completion / 100) * 100) : 0;
+
+ return (
+
+
+ {appointments > 0 && (
+
+ )}
+ {completion > 0 && (
+
+ )}
+
+
+ Period {item.period}
+
+
+ );
+ })
+ ) : (
+
+
No chart data available
+
+ )}
+
+
+
+
{chartData?.reduce((sum, item) => sum + (item.interactions || 0), 0) || 0}
+
Total This {timeRange}
+
+
+
{analyticsData?.quickStats?.satisfactionRate?.value || 0}%
+
Average Completion
+
+
+
{analyticsData?.quickStats?.avgResponseTime?.value || 0}min
+
Avg Response Time
+
+
+
+
+ {/* Skills Overview */}
+
+
Performance Skills
+
+ {skillsData.length > 0 ? skillsData.map((skill, index: number) => (
+
+
+
+
+
+ {skill.proficiency}%
+
+
+
+
{skill.skill}
+
+ )) : (
+
+ No skills data available
+
+ )}
+
+
+
+ {/* Service Types */}
+
+
Service Types Handled
+
+ {commonQueries.length > 0 ? commonQueries.map((query, index: number) => (
+
+
+
+ {index + 1}
+
+
+
{query.type}
+
{query.count} appointments
+
+
+
+
{query.percentage}%
+
+ {query.trend === 'up' ? '↗' : query.trend === 'down' ? '↘' : '→'} {query.trend}
+
+
+
+ )) : (
+
+ No service type data available
+
+ )}
+
+
+
+ {/* Resource Usage */}
+
+
Current Performance Metrics
+
+ {resourceData.length > 0 ? resourceData.map((resource, index: number) => (
+
+
+
+ {resource.value}%
+
+
+
+
{resource.name}
+
+ {resource.status}
+
+
+ )) : (
+
+ No resource data available
+
+ )}
+
+
+
+ {/* Personal Metrics Summary */}
+
+
Personal Performance Summary
+
+ {Object.keys(personalMetrics).length > 0 ? Object.entries(personalMetrics).slice(0, 6).map(([key, metric]) => (
+
+
+
+ {key.replace(/([A-Z])/g, ' $1').toLowerCase()}
+
+
+ {metric.trend && metric.trend > 0 ? '+' : ''}{metric.trend || 0}%
+
+
+
+ {metric.value}{metric.unit}
+
+
+ )) : (
+
+ No personal metrics available
+
+ )}
+
+
+
+ {/* Data Summary */}
+
+ Last updated: {new Date().toLocaleTimeString()} •
+ Showing {timeRange} data •
+ {chartData?.reduce((sum, item) => sum + (item.interactions || 0), 0) || 0} total appointments
+
+
+ );
+};
+
+export default SimplifiedAnalytics;
\ No newline at end of file
diff --git a/src/components/agent/analytics/SystemTrends.tsx b/src/components/agent/analytics/SystemTrends.tsx
index 5d0cdd2..6466c27 100644
--- a/src/components/agent/analytics/SystemTrends.tsx
+++ b/src/components/agent/analytics/SystemTrends.tsx
@@ -1,6 +1,6 @@
// src/components/agent/analytics/SystemTrends.tsx
"use client";
-import React, { useState, useEffect } from 'react';
+import React, { useState, useEffect, useCallback } from 'react';
// Types
type Language = 'en' | 'si' | 'ta';
@@ -238,86 +238,60 @@ const SystemTrends: React.FC