import React, { useState } from 'react'; import { Upload, FileText, CheckCircle2, TrendingUp, ThumbsUp, ThumbsDown, Download, RefreshCw, BarChart3, Database } from 'lucide-react'; import { uploadBatchCSV, getSampleBatch } from '../../services/api'; export default function BatchAnalytics() { const [loading, setLoading] = useState(false); const [data, setData] = useState(null); const [error, setError] = useState(null); const [searchTerm, setSearchTerm] = useState(''); const [sentimentFilter, setSentimentFilter] = useState('ALL'); const handleFileUpload = async (e) => { const file = e.target.files[0]; if (!file) return; setLoading(true); setError(null); try { const res = await uploadBatchCSV(file); setData(res); } catch (err) { setError(err.message); } finally { setLoading(false); } }; const handleLoadSample = async () => { setLoading(true); setError(null); try { const res = await getSampleBatch(); setData(res); } catch (err) { setError(err.message); } finally { setLoading(false); } }; const handleExportCSV = () => { if (!data || !data.reviews) return; const headers = ["ID", "Product", "Review Text", "Sentiment", "Confidence (%)", "Primary Aspect"]; const rows = data.reviews.map(r => [ r.id, r.product ? `"${r.product.replace(/"/g, '""')}"` : "N/A", `"${r.text.replace(/"/g, '""')}"`, r.sentiment, r.confidence, r.primary_aspect ]); const csvContent = "data:text/csv;charset=utf-8," + [headers.join(","), ...rows.map(e => e.join(","))].join("\n"); const encodedUri = encodeURI(csvContent); const link = document.createElement("a"); link.setAttribute("href", encodedUri); link.setAttribute("download", `sentiment_batch_analysis_${Date.now()}.csv`); document.body.appendChild(link); link.click(); document.body.removeChild(link); }; const filteredReviews = data?.reviews?.filter(r => { const matchesSearch = r.text.toLowerCase().includes(searchTerm.toLowerCase()) || (r.product && r.product.toLowerCase().includes(searchTerm.toLowerCase())); const matchesSentiment = sentimentFilter === 'ALL' || r.sentiment.toUpperCase() === sentimentFilter; return matchesSearch && matchesSentiment; }) || []; return (
{/* Upload and Sample Panel */}

Batch Reviews & E-Commerce Executive Analytics

Process entire product catalogs or batches of Amazon customer reviews with GPU acceleration.

{error && (
{error}
)} {loading && !data && (

Executing high-throughput batch inference and aspect decomposition on GPU...

)} {data && (
{/* Executive KPI Row */}
Total Processed
{data.total_reviews} Reviews
Full batch analysis
Sentiment Ratio
{data.positive_pct}% / {data.negative_pct}%
{data.positive_count} Pos · {data.negative_count} Neg
Net Promoter Score (NPS)
30 ? 'text-accent-emerald' : data.nps_metrics.nps_score > 0 ? 'text-accent-amber' : 'text-accent-rose' }`}> {data.nps_metrics.nps_score > 0 ? `+${data.nps_metrics.nps_score}` : data.nps_metrics.nps_score}
Tier: {data.nps_metrics.classification}
Customer Stance Breakdown
{data.nps_metrics.promoters_pct}% Promoters · {data.nps_metrics.detractors_pct}% Detractors
Passives: {data.nps_metrics.passives_pct}%
{/* Aspect Breakdown & Driver Keywords */}
{/* Aspect Satisfaction Breakdown */}

Aspect Satisfaction Breakdown Across Batch

{data.aspect_breakdown && data.aspect_breakdown.map((asp, idx) => (
{asp.aspect} {asp.satisfaction_rate}% Positive ({asp.total_mentions} mentions)
))}
{/* Top Driver Keywords */}

Top Sentiment Drivers & Complaint Themes

Positive Product Highlights
{data.top_positive_drivers.map((w, i) => ( {w.word} ({w.count}) ))}
Frequent Defect / Complaint Themes
{data.top_complaint_themes.map((w, i) => ( {w.word} ({w.count}) ))}
{/* Processed Reviews Table */}
setSearchTerm(e.target.value)} className="bg-bg-base border border-border-strong text-text-primary text-xs rounded-lg px-3 py-1.5 focus:outline-none focus:border-accent-indigo w-64" />
{filteredReviews.map((r, idx) => ( ))}
# Product Review Sentiment Confidence Primary Aspect
{r.id} {r.product || 'Amazon Item'} "{r.text}" {r.sentiment} {r.confidence}% {r.primary_aspect}
)}
); }