'use client'; import React, { useState, useEffect } from 'react'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { Badge } from '@/components/ui/badge'; import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs'; import { ScrollArea } from '@/components/ui/scroll-area'; import { Separator } from '@/components/ui/separator'; import { Brain, Lightbulb, TrendingUp, AlertTriangle, CheckCircle, Info, RefreshCw, Download, Filter, Calendar, Target, Activity } from 'lucide-react'; import { AnalyticsInsight, LLMAnalysisResponse } from '@/lib/types/analytics'; import { cn } from '@/lib/utils'; interface AnalysisPanelProps { insights: AnalyticsInsight[]; llmAnalysis?: LLMAnalysisResponse; loading?: boolean; onRefresh?: () => void; onExport?: () => void; className?: string; } export function AnalysisPanel({ insights, llmAnalysis, loading = false, onRefresh, onExport, className }: AnalysisPanelProps) { const [activeTab, setActiveTab] = useState('insights'); const [filter, setFilter] = useState<'all' | 'warnings' | 'recommendations' | 'success'>('all'); // Filter insights based on selected filter const filteredInsights = insights.filter(insight => { switch (filter) { case 'warnings': return insight.type === 'warning' || insight.type === 'error'; case 'recommendations': return insight.actionable === true && insight.recommendation; case 'success': return insight.type === 'success'; default: return true; } }); // Group insights by category const insightsByCategory = filteredInsights.reduce((groups, insight) => { if (!groups[insight.category]) { groups[insight.category] = []; } groups[insight.category].push(insight); return groups; }, {} as Record); const getInsightIcon = (type: string) => { switch (type) { case 'success': return ; case 'warning': return ; case 'error': return ; case 'info': default: return ; } }; const getInsightColor = (type: string) => { switch (type) { case 'success': return 'border-green-200 bg-green-50'; case 'warning': return 'border-yellow-200 bg-yellow-50'; case 'error': return 'border-red-200 bg-red-50'; case 'info': default: return 'border-blue-200 bg-blue-50'; } }; const getSeverityColor = (severity?: string) => { switch (severity) { case 'high': return 'bg-red-100 text-red-800'; case 'medium': return 'bg-yellow-100 text-yellow-800'; case 'low': default: return 'bg-gray-100 text-gray-800'; } }; const getCategoryIcon = (category: string) => { switch (category) { case 'activity': return ; case 'content': return ; case 'timeliness': return ; case 'patterns': return ; case 'recommendations': return ; default: return ; } }; if (loading) { return ( AI Analysis

Analyzing time entries...

); } return (
AI Analysis & Insights
{onRefresh && ( )} {onExport && ( )}
{/* Summary Stats */}
{insights.length}
Total Insights
{insights.filter(i => i.type === 'success').length}
Positive
{insights.filter(i => i.type === 'warning').length}
Warnings
{insights.filter(i => i.type === 'error').length}
Issues
Insights Patterns Recommendations {llmAnalysis && AI Analysis} {/* Filter */}
{filteredInsights.length === 0 ? (

No insights found for the selected filter

) : (
{Object.entries(insightsByCategory).map(([category, categoryInsights]) => (
{getCategoryIcon(category)}

{category}

{categoryInsights.length}
{categoryInsights.map((insight, index) => (
{getInsightIcon(insight.type)}

{insight.title}

{insight.severity && ( {insight.severity} )} {insight.actionable && ( Actionable )}

{insight.description}

{insight.recommendation && (

Recommendation:

{insight.recommendation}

)}
))}
))}
)}
{llmAnalysis?.patterns && llmAnalysis.patterns.length > 0 ? (
{llmAnalysis.patterns.map((pattern, index) => (

{pattern.type}

{pattern.frequency} occurrences {pattern.impact} impact

{pattern.description}

))}
) : (

No patterns detected yet

AI analysis will identify recurring work patterns

)}
{llmAnalysis?.recommendations && llmAnalysis.recommendations.length > 0 ? (
{llmAnalysis.recommendations.map((rec, index) => (

{rec.category}

{rec.priority} priority

{rec.action}

Expected Impact: {rec.expectedImpact}
))}
) : (

No recommendations available yet

AI will provide actionable recommendations based on analysis

)}
{llmAnalysis && (
{/* Summary */}

AI Summary

Overall Quality
{Math.round(llmAnalysis.summary.overallQuality * 100)}%
Productivity Level
{Math.round(llmAnalysis.summary.productivityLevel * 100)}%
{llmAnalysis.summary.keyFindings.length > 0 && (
Key Findings
    {llmAnalysis.summary.keyFindings.map((finding, index) => (
  • {finding}
  • ))}
)}
{/* Processing Info */}
Processing time: {llmAnalysis.processingTime}ms Tokens used: {llmAnalysis.tokensUsed}
)}
); }