"use client"; import React, { useState } from "react"; import { CheckCircle2, XCircle, AlertTriangle, TrendingUp, TrendingDown, Globe, Lightbulb, AlertCircle, ChevronDown, ChevronUp, Image as ImageIcon, Tag, Users, Brain, ThumbsUp, ThumbsDown, Zap } from "lucide-react"; interface AnalysisResultsProps { data: any; onFeedback?: (feedbackType: 'correct' | 'incorrect' | 'aggressive' | 'lenient') => void; } export function AnalysisResults({ data, onFeedback }: AnalysisResultsProps) { const [activeTab, setActiveTab] = useState<'overview' | 'details' | 'sources' | 'images'>('overview'); const [expandedSections, setExpandedSections] = useState>({ overview: true, correct: true, wrong: true, internet: true, recommendation: true, matters: true }); const [feedbackGiven, setFeedbackGiven] = useState(false); const [showFeedback, setShowFeedback] = useState(true); if (!data || !data.success) { return (

Analysis Failed

{data?.error || 'Unable to analyze content. Please try again.'}

); } const percentage = data.misinformation_percentage || 0; const verdict = data.verdict || 'UNKNOWN'; // Determine color scheme based on percentage let verdictColor = 'text-green-400'; let bgGradient = 'from-green-500/20 to-emerald-500/20'; let borderColor = 'border-green-500/30'; if (percentage > 60) { verdictColor = 'text-red-400'; bgGradient = 'from-red-500/20 to-rose-500/20'; borderColor = 'border-red-500/30'; } else if (percentage > 30) { verdictColor = 'text-yellow-400'; bgGradient = 'from-yellow-500/20 to-amber-500/20'; borderColor = 'border-yellow-500/30'; } const toggleSection = (section: string) => { setExpandedSections(prev => ({ ...prev, [section]: !prev[section] })); }; return (
{/* Verdict Card - Mobile optimized */}
{percentage < 30 ? ( ) : percentage < 60 ? ( ) : ( )}

{verdict}

{data.title && (

{data.title}

)}
{percentage.toFixed(1)}%
Risk Score
{/* Progress Bar - Slimmer on mobile */}
{/* Quick Stats - Compact on mobile */} {data.overall && (
{data.overall.total_paragraphs || 0}
Total Paragraphs
{data.overall.fake_paragraphs || 0}
High Risk
{data.overall.suspicious_paragraphs || 0}
Medium Risk
)}
{/* Tabs - Horizontal scroll on mobile */}
{['overview', 'details', 'sources', 'images'].map((tab) => ( ))}
{/* Tab Content - Mobile optimized spacing */}
{activeTab === 'overview' && ( <> {/* Categories */} {data.pretrained_models?.categories && data.pretrained_models.categories.length > 0 && (
} gradient="from-yellow-500/20 to-amber-500/20">
{data.pretrained_models.categories.map((cat: string, idx: number) => ( {cat} ))}
)} {/* Entities */} {data.pretrained_models?.named_entities && data.pretrained_models.named_entities.length > 0 && (
} gradient="from-purple-500/20 to-pink-500/20">
{data.pretrained_models.named_entities.slice(0, 10).map((entity: string, idx: number) => ( {entity} ))}
)} {/* What's Correct */} {data.what_is_right && data.what_is_right !== 'See conclusion' && data.what_is_right !== 'See full conclusion' && ( } gradient="from-green-500/20 to-emerald-500/20" borderColor="border-green-500/30" isExpanded={expandedSections.correct} onToggle={() => toggleSection('correct')} >
{data.what_is_right.replace(/\*\*/g, '').replace(/WHAT IS CORRECT:/gi, '').trim()}
)} {/* What's Wrong */} {data.what_is_wrong && data.what_is_wrong !== 'See conclusion' && data.what_is_wrong !== 'See full conclusion' && ( } gradient="from-red-500/20 to-rose-500/20" borderColor="border-red-500/30" isExpanded={expandedSections.wrong} onToggle={() => toggleSection('wrong')} >
{data.what_is_wrong.replace(/\*\*/g, '').replace(/WHAT IS WRONG:/gi, '').trim()}
)} {/* What Internet Says */} {data.internet_says && data.internet_says !== 'See conclusion' && data.internet_says !== 'See full conclusion' && ( } gradient="from-blue-500/20 to-cyan-500/20" borderColor="border-blue-500/30" isExpanded={expandedSections.internet} onToggle={() => toggleSection('internet')} >
{data.internet_says.replace(/\*\*/g, '').replace(/WHAT THE INTERNET SAYS:/gi, '').trim()}
)} {/* Recommendation */} {data.recommendation && data.recommendation !== 'Verify with credible sources' && data.recommendation.length > 30 && ( } gradient="from-yellow-500/20 to-amber-500/20" borderColor="border-yellow-500/30" isExpanded={expandedSections.recommendation} onToggle={() => toggleSection('recommendation')} >
{data.recommendation.replace(/\*\*/g, '').replace(/MY RECOMMENDATION:/gi, '').replace(/RECOMMENDATION:/gi, '').trim()}
)} {/* Why It Matters */} {data.why_matters && data.why_matters !== 'Critical thinking is essential' && data.why_matters.length > 30 && ( } gradient="from-purple-500/20 to-violet-500/20" borderColor="border-purple-500/30" isExpanded={expandedSections.matters} onToggle={() => toggleSection('matters')} >
{data.why_matters.replace(/\*\*/g, '').replace(/WHY THIS MATTERS:/gi, '').replace(/Why this matters:/gi, '').trim()}
)} )} {activeTab === 'details' && ( <> {/* Combined Credibility Analysis - EXACTLY Like Extension */} {data.combined_analysis && (
} gradient="from-white/5 to-white/10" borderColor="border-orange-500/20" >
{/* Credibility Meter */}
Risk Score {Math.round(data.combined_analysis.overall_score || 0)}/100
{/* Meter Bar */}
50 ? '#ef4444' : (data.combined_analysis.overall_score || 0) > 35 ? '#f59e0b' : (data.combined_analysis.overall_score || 0) > 20 ? '#3b82f6' : '#10b981' }, ${ (data.combined_analysis.overall_score || 0) > 50 ? '#dc2626dd' : (data.combined_analysis.overall_score || 0) > 35 ? '#d97706dd' : (data.combined_analysis.overall_score || 0) > 20 ? '#2563ebdd' : '#059669dd' })` }} />
50 ? 'white' : '#1f2937' }}> {data.combined_analysis.verdict || 'UNKNOWN'}
{/* Legend */}
0 - Highly Credible 100 - Not Credible
{/* Quick Stats */} {data.overall && (
{data.overall.fake_paragraphs || 0}
High Risk Paragraphs
{data.overall.suspicious_paragraphs || 0}
Medium Risk Paragraphs
)} {/* Detection Systems Note */}
📊 Analysis Based On: 8 detection systems including linguistic patterns, claim verification, source credibility, entity verification, propaganda detection, network analysis, contradiction detection, and AI propagation analysis.
)} {/* Suspicious Items */} {data.chunks && data.chunks.length > 0 && (
}>
{data.chunks.slice(0, 10).map((chunk: any, idx: number) => (
Paragraph {chunk.index + 1} {chunk.suspicious_score}/100

"{chunk.text_preview}"

{chunk.why_flagged && (

{chunk.why_flagged}

)}
))}
)} )} {activeTab === 'sources' && ( <> {/* Research Sources */} {((data.research_sources && data.research_sources.length > 0) || (data.sources_found && data.sources_found.length > 0)) ? (
}>
{(data.research_sources || data.sources_found || []).map((source: any, idx: number) => { const isString = typeof source === 'string'; const url = isString ? source : (source.url || source.link || '#'); const title = isString ? `Source ${idx + 1}` : (source.title || source.name || `Source ${idx + 1}`); const snippet = !isString && source.snippet ? source.snippet : ''; return (
{title}
{snippet && (
{snippet}
)}
{url}
); })}
) : (
}>

No external sources were found for verification.

This could mean the content is unique or not widely covered.

)} )} {activeTab === 'images' && ( <> {data.image_analysis && data.image_analysis.analyzed_images > 0 ? ( <>
} gradient={data.image_analysis.ai_generated_count > 0 ? "from-red-500/20 to-rose-500/20" : "from-green-500/20 to-emerald-500/20"} >

{data.image_analysis.summary}

{data.image_analysis.analyzed_images}
Analyzed
{data.image_analysis.ai_generated_count}
AI-Generated
{data.image_analysis.real_images_count || 0}
Real Photos
) : (
}>

{data.image_analysis?.total_images === 0 ? '📷 No images found on this page' : '🖼️ No image analysis data available'}

)} )}
{/* RL Feedback Section */} {showFeedback && !feedbackGiven && (

Help Improve AI Accuracy

Your feedback trains our AI to be more accurate over time using Reinforcement Learning!

)} {/* Feedback Success Message */} {feedbackGiven && showFeedback && (

✅ Thank you! Your feedback helps improve our AI accuracy.

)}
); } // Helper Components - Mobile optimized function PhaseCard({ title, score, icon, details }: { title: string; score: number; icon: string; details: string[] }) { const percentage = Math.min(Math.max(score, 0), 100); let barColor = 'from-green-400 to-emerald-500'; let bgColor = 'bg-green-500/10'; let borderColor = 'border-green-500/30'; if (percentage > 70) { barColor = 'from-red-400 to-rose-500'; bgColor = 'bg-red-500/10'; borderColor = 'border-red-500/30'; } else if (percentage > 40) { barColor = 'from-yellow-400 to-amber-500'; bgColor = 'bg-yellow-500/10'; borderColor = 'border-yellow-500/30'; } return (
{icon}
{title}
{percentage.toFixed(0)}%
{details && details.length > 0 && (
{details.map((detail, idx) => (
{detail}
))}
)}
); } function ScoreMeter({ label, score, description }: { label: string; score: number; description?: string }) { const percentage = Math.min(Math.max(score, 0), 100); let barColor = 'bg-gradient-to-r from-green-400 to-emerald-500'; if (percentage > 70) { barColor = 'bg-gradient-to-r from-red-400 to-rose-500'; } else if (percentage > 40) { barColor = 'bg-gradient-to-r from-yellow-400 to-amber-500'; } return (
{label} {percentage.toFixed(1)}%
{description && (

{description}

)}
); } function Section({ title, icon, children, gradient = "from-white/5 to-white/10", borderColor = "border-orange-500/20" }: { title: string; icon?: React.ReactNode; children: React.ReactNode; gradient?: string; borderColor?: string; }) { return (
{icon}

{title}

{children}
); } function CollapsibleSection({ title, icon, children, gradient = "from-white/5 to-white/10", borderColor = "border-orange-500/20", isExpanded, onToggle }: { title: string; icon?: React.ReactNode; children: React.ReactNode; gradient?: string; borderColor?: string; isExpanded: boolean; onToggle: () => void; }) { return (
{isExpanded && (
{children}
)}
); }