import React, { useState, useEffect } from 'react'
import { X } from 'lucide-react'
import { BarChart, Bar, XAxis, YAxis, Tooltip, ResponsiveContainer, PieChart, Pie, Cell, AreaChart, Area } from 'recharts'
const COLORS = ['#3B82F6', '#10B981', '#F97316', '#A855F7', '#EC4899', '#FBBF24', '#14B8A6', '#EF4444', '#6366F1', '#84CC16']
export default function AnalyticsPanel({ onClose }) {
const [overview, setOverview] = useState(null)
const [sectorData, setSectorData] = useState(null)
const [loading, setLoading] = useState(true)
const [activeTab, setActiveTab] = useState('overview')
useEffect(() => {
Promise.all([
fetch('/api/entities/analytics/overview').then(r => r.json()),
fetch('/api/entities/analytics/sectors').then(r => r.json()),
]).then(([ov, sd]) => {
setOverview(ov)
setSectorData(sd)
setLoading(false)
}).catch(console.error)
}, [])
const CustomTooltip = ({ active, payload, label }) => {
if (!active || !payload?.length) return null
return (
{label}
{payload.map((p, i) => (
{p.name}: {typeof p.value === 'number' ? p.value.toLocaleString() : p.value}
))}
)
}
return (
π Analytics
Curated dataset β not total Indian ecosystem
{[
{ id: 'overview', label: 'π Overview' },
{ id: 'sectors', label: 'π Sectors' },
{ id: 'geography', label: 'πΊοΈ Geography' },
{ id: 'trends', label: 'π Trends' },
].map(tab => (
))}
{loading ? (
{[...Array(4)].map((_, i) => (
))}
) : (
<>
{activeTab === 'overview' && overview && (
<>
{/* Disclaimer */}
β Curated dataset of {overview.total_entities?.toLocaleString()} mapped entities.
India has 223,000+ DPIIT-recognized startups and 102,000+ women-led ventures.
Figures below reflect our database only.
{/* Entity Type Pie Chart */}
Entity Distribution
({ name: k.replace('_', ' '), value: v }))}
cx="50%" cy="50%" outerRadius="80%" innerRadius="50%"
dataKey="value" nameKey="name"
stroke="none"
>
{Object.keys(overview.by_type || {}).map((_, i) => (
|
))}
} />
{Object.entries(overview.by_type || {}).sort((a, b) => b[1] - a[1]).map(([type, count], i) => (
{type.replace('_', ' ')}
({count.toLocaleString()})
))}
>
)}
{activeTab === 'sectors' && sectorData && (
Mapped Entities by Sector
({ name: s.sector.replace('_', ' '), count: s.count, funding: s.total_employees }))} layout="vertical" margin={{ left: 80, right: 20 }}>
} />
{sectorData.slice(0, 10).map((s, i) => (
#{i + 1}
{s.sector.replace('_', ' ')}
{s.count}
{s.total_funding_display}
))}
)}
{activeTab === 'geography' && overview && (
Top States (mapped)
({ name: s.state, count: s.count }))} layout="vertical" margin={{ left: 90, right: 20 }}>
} />
{(overview.top_states || []).map((_, i) => (
|
))}
Top Cities (mapped)
{(overview.top_cities || []).map((c, i) => (
{c.state} β’ {c.count.toLocaleString()} entities
))}
)}
{activeTab === 'trends' && overview && (
Founding Trend (mapped entities, 2005βPresent)
{overview.founding_trend?.length > 0 && (
)}
)}
>
)}
)
}
function StatCard({ label, value, color }) {
return (
)
}