'use client'; import { Star, TrendingUp, TrendingDown, Minus, AlertTriangle, CheckCircle, Quote, ArrowRight, Zap, Clock, Target, Users, MessageSquare, Trophy, Megaphone } from 'lucide-react'; import type { LegacySynthesis, SentimentDataPoint, URTDomainPoint, TimelinePoint, OverviewStats, ReportAction, ReportEvidence, ReportStrength, } from './types'; // Domain config const DOMAINS: Record = { P: { emoji: '๐Ÿ‘ฅ', label: 'Staff & Service' }, V: { emoji: '๐Ÿ’ฐ', label: 'Pricing & Value' }, J: { emoji: 'โฑ๏ธ', label: 'Speed & Process' }, O: { emoji: '๐Ÿ›๏ธ', label: 'Product Quality' }, A: { emoji: '๐Ÿ“', label: 'Availability' }, E: { emoji: '๐Ÿข', label: 'Facilities' }, R: { emoji: '๐Ÿค', label: 'Trust & Ethics' }, }; interface AnalystReportProps { synthesis: LegacySynthesis; overview: OverviewStats; sentiment: SentimentDataPoint[]; domains: URTDomainPoint[]; timeline: TimelinePoint[]; } /** * The Analyst Report - A consultant-quality business narrative. * Replaces widget soup with a flowing, story-driven report. */ export function AnalystReport({ synthesis, overview, sentiment, domains, timeline }: AnalystReportProps) { const positivePct = sentiment.find(s => s.valence === 'V+')?.percentage || 0; const negativePct = sentiment.find(s => s.valence === 'V-')?.percentage || 0; return (
{/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• THE VERDICT โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */}
{/* Rating Display */}
{synthesis.current_rating.toFixed(1)}
{[1, 2, 3, 4, 5].map((star) => ( ))}
{overview.total_reviews.toLocaleString()} reviews
{/* Rating Potential */} {synthesis.rating_gap > 0 && (
+{synthesis.rating_gap.toFixed(1)}
potential if fixed
)}
{/* Headline */}

{synthesis.headline}

{/* Verdict */}

{synthesis.verdict}

{/* Momentum Indicator */} {synthesis.momentum && synthesis.momentum_detail && ( )}
{/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• THE STORY โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */}

Executive Summary

{synthesis.narrative.split('\n\n').map((paragraph, i) => (

{paragraph}

))}
{/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• THE DIAGNOSIS โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */} {synthesis.primary_problem && (

Primary Issue

{synthesis.primary_problem}

{synthesis.root_cause && (

Root cause: {synthesis.root_cause}

)}
)} {/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• THE STRENGTHS (What to Protect) โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */} {synthesis.strengths && synthesis.strengths.length > 0 && ( )} {/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• THE EVIDENCE โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */} {synthesis.evidence.length > 0 && (

What Customers Are Saying

{synthesis.evidence.map((item, i) => ( ))}
)} {/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• THE DATA (Visual Support) โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */}
{/* Sentiment */}

{synthesis.sentiment_headline || 'Sentiment Breakdown'}

{/* Categories */}

{synthesis.category_headline || 'Category Performance'}

{domains.slice(0, 4).map((d) => ( ))}
{/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• THE ACTION PLAN (Enhanced) โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */} {synthesis.actions.length > 0 && ( )} {/* โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• FOOTER โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• */}
Report generated {new Date(synthesis.generated_at).toLocaleDateString()} {' ยท '}{synthesis.review_count} reviews ยท {synthesis.insight_count} insights extracted
); } // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• // Momentum Badge // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• function MomentumBadge({ momentum, detail }: { momentum: string; detail: string }) { const config = { improving: { icon: , bg: 'bg-emerald-500/20', text: 'text-emerald-300', label: 'Improving', }, declining: { icon: , bg: 'bg-red-500/20', text: 'text-red-300', label: 'Declining', }, stable: { icon: , bg: 'bg-slate-500/20', text: 'text-slate-300', label: 'Stable', }, }; const c = config[momentum as keyof typeof config] || config.stable; return (
{c.icon} {c.label} ยท {detail}
); } // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• // Strengths Section // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• function StrengthsSection({ strengths }: { strengths: ReportStrength[] }) { return (

Your Strengths

Protect and leverage these competitive advantages

{strengths.map((strength, i) => ( ))}
); } function StrengthCard({ strength }: { strength: ReportStrength }) { return (
{/* Header */}

{strength.title}

{strength.mention_count} mentions
{/* Quote */} {strength.quote && (

"{strength.quote}"

)} {/* Marketing Angle */} {strength.marketing_angle && (

Marketing: {strength.marketing_angle}

)}
); } // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• // Action Plan Section (Enhanced) // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• function ActionPlanSection({ actions, ratingGap }: { actions: ReportAction[]; ratingGap: number }) { // Group actions by effort/timeline const quickWins = actions.filter(a => a.effort === 'quick_win'); const moderate = actions.filter(a => a.effort === 'moderate'); const strategic = actions.filter(a => a.effort === 'strategic'); // Calculate totals const totalImpact = actions.reduce((sum, a) => sum + (a.impact_stars || 0), 0); const totalComplaints = actions.reduce((sum, a) => sum + (a.complaint_count || 0), 0); return (
{/* Header with Impact Summary */}

Action Plan

{actions.length} actions to gain +{totalImpact.toFixed(1)}โ˜…

Addresses {totalComplaints} complaints
{/* Impact Progress Bar */}
Potential Impact
+{totalImpact.toFixed(1)}โ˜…
{/* Action Groups */}
{/* Quick Wins */} {quickWins.length > 0 && ( } iconBg="bg-amber-100 text-amber-600" actions={quickWins} /> )} {/* This Quarter */} {moderate.length > 0 && ( } iconBg="bg-blue-100 text-blue-600" actions={moderate} /> )} {/* Strategic */} {strategic.length > 0 && ( } iconBg="bg-purple-100 text-purple-600" actions={strategic} /> )}
); } function ActionGroup({ title, subtitle, icon, iconBg, actions, }: { title: string; subtitle: string; icon: React.ReactNode; iconBg: string; actions: ReportAction[]; }) { return (
{/* Group Header */}
{icon}

{title}

{subtitle}

{/* Actions */}
{actions.map((action, i) => ( ))}
); } function EnhancedActionCard({ action }: { action: ReportAction }) { const priorityConfig = { critical: { bg: 'bg-red-50 border-red-200', badge: 'bg-red-100 text-red-700', label: 'Critical' }, high: { bg: 'bg-orange-50 border-orange-200', badge: 'bg-orange-100 text-orange-700', label: 'High' }, medium: { bg: 'bg-slate-50 border-slate-200', badge: 'bg-slate-100 text-slate-700', label: 'Medium' }, }; const config = priorityConfig[action.priority as keyof typeof priorityConfig] || priorityConfig.medium; return (
{/* Action Title */}

{action.action}

{/* Meta Grid */}
{/* Priority */}
{config.label}
{/* Owner */}
{action.owner}
{/* Impact */}
{action.impact}
{/* Complaints */} {action.complaint_count > 0 && (
{action.complaint_count} complaints
)}
{/* Evidence Quote */} {action.evidence && (
"{action.evidence}"
)} {/* Success Metric */} {action.success_metric && (
Success: {action.success_metric}
)}
); } // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• // Sub-components // โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ• function EvidenceCard({ evidence }: { evidence: ReportEvidence }) { const isDamaging = evidence.sentiment === 'damaging'; return (

"{evidence.quote}"

{evidence.context}

); } function SentimentBar({ positive, negative }: { positive: number; negative: number }) { const neutral = Math.max(0, 100 - positive - negative); return (
{positive.toFixed(0)}% positive {negative.toFixed(0)}% negative
); } function DomainRow({ domain }: { domain: URTDomainPoint }) { const config = DOMAINS[domain.domain] || { emoji: '๐Ÿ“Š', label: domain.domain_name }; const total = domain.positive_count + domain.negative_count; const negativePct = total > 0 ? (domain.negative_count / total) * 100 : 0; const status = negativePct > 40 ? 'critical' : negativePct > 25 ? 'warning' : 'good'; const statusColors = { critical: 'text-red-600', warning: 'text-orange-600', good: 'text-emerald-600', }; return (
{config.emoji} {config.label} {negativePct.toFixed(0)}% issues
); }