import React from "react"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Button } from "@/components/ui/button"; import { Download, Zap, Clock, TrendingUp, CheckCircle } from "lucide-react"; import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ResponsiveContainer, PieChart, Pie, Cell } from "recharts"; import { Badge } from "@/components/ui/badge"; import { useToast } from "@/components/ui/use-toast"; const COLORS = ['#10b981', '#3b82f6', '#f59e0b', '#ef4444']; export default function OperationalEfficiencyReport({ events, staff }) { const { toast } = useToast(); // Automation impact metrics const totalEvents = events.length; const autoAssignedEvents = events.filter(e => e.assigned_staff && e.assigned_staff.length > 0 ).length; const automationRate = totalEvents > 0 ? ((autoAssignedEvents / totalEvents) * 100).toFixed(1) : 0; // Fill rate by status const statusBreakdown = events.reduce((acc, event) => { const status = event.status || 'Draft'; acc[status] = (acc[status] || 0) + 1; return acc; }, {}); const statusData = Object.entries(statusBreakdown).map(([name, value]) => ({ name, value, })); // Time to fill metrics const avgTimeToFill = 2.3; // Mock - would calculate from event creation to full assignment const avgResponseTime = 1.5; // Mock - hours to respond to requests // Efficiency over time const efficiencyTrend = [ { month: 'Jan', automation: 75, fillRate: 88, responseTime: 2.1 }, { month: 'Feb', automation: 78, fillRate: 90, responseTime: 1.9 }, { month: 'Mar', automation: 82, fillRate: 92, responseTime: 1.7 }, { month: 'Apr', automation: 85, fillRate: 94, responseTime: 1.5 }, ]; const handleExport = () => { const csv = [ ['Operational Efficiency Report'], ['Generated', new Date().toISOString()], [''], ['Summary Metrics'], ['Total Events', totalEvents], ['Auto-Assigned Events', autoAssignedEvents], ['Automation Rate', `${automationRate}%`], ['Avg Time to Fill (hours)', avgTimeToFill], ['Avg Response Time (hours)', avgResponseTime], [''], ['Status Breakdown'], ['Status', 'Count'], ...Object.entries(statusBreakdown).map(([status, count]) => [status, count]), [''], ['Efficiency Trend'], ['Month', 'Automation %', 'Fill Rate %', 'Response Time (hrs)'], ...efficiencyTrend.map(t => [t.month, t.automation, t.fillRate, t.responseTime]), ].map(row => row.join(',')).join('\n'); const blob = new Blob([csv], { type: 'text/csv' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `operational-efficiency-${new Date().toISOString().split('T')[0]}.csv`; document.body.appendChild(a); a.click(); document.body.removeChild(a); URL.revokeObjectURL(url); toast({ title: "✅ Report Exported", description: "Efficiency report downloaded as CSV" }); }; return (
Track process improvements and automation effectiveness
Automation Rate
{automationRate}%
Avg Time to Fill
{avgTimeToFill}h
Response Time
{avgResponseTime}h
Completed
{events.filter(e => e.status === 'Completed').length}
Manual Work Reduction
85%
First-Time Fill Rate
92%
Staff Utilization
88%
Conflict Detection
97%