"use client" import React, { useEffect, useState } from 'react'; import { motion } from 'framer-motion'; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { BarChart, X, Users, Activity, Loader2 } from 'lucide-react'; import { Button } from '@/components/ui/button'; interface DistributionChartProps { onClose: () => void; } interface StatsData { total_patients: number; avg_age: number; gender_distribution: { Male: number; Female: number }; age_bins?: { bin: string; count: number }[]; // We might need to fetch this or simulate } export default function DistributionChart({ onClose }: DistributionChartProps) { const [stats, setStats] = useState(null); const [loading, setLoading] = useState(true); useEffect(() => { const fetchStats = async () => { try { // In a real app we'd fetch histogram data // For now reusing /stats and simulating bins for demo const endpoint = process.env.NEXT_PUBLIC_API_URL || '/api'; const res = await fetch(`${endpoint}/stats`); if (res.ok) { const data = await res.json(); setStats(data); } } catch (error) { console.error(error); } finally { setLoading(false); } }; fetchStats(); }, []); const maxCount = stats ? Math.max(stats.gender_distribution.Male, stats.gender_distribution.Female) : 100; return ( Patient Distribution Analysis {loading ? (
) : stats ? (
{/* Summary Stats */}
Total Patients
{stats.total_patients.toLocaleString()}
Average Age
{stats.avg_age} years

Data Overview

The dataset covers {stats.total_patients.toLocaleString()} distinct ICU stays. Analysis shows a predominance of {stats.gender_distribution.Male > stats.gender_distribution.Female ? 'male' : 'female'} patients ({Math.round(stats.gender_distribution.Male / stats.total_patients * 100)}% vs {Math.round(stats.gender_distribution.Female / stats.total_patients * 100)}%). The cohort represents a diverse age range typical for sepsis studies.

{/* Visualization */}

Gender Distribution

{/* Male Bar */}
Male {stats.gender_distribution.Male.toLocaleString()}
{/* Female Bar */}
Female {stats.gender_distribution.Female.toLocaleString()}

Dataset Coverage

Age histogram not available in this view

{/* Placeholder for 3D effect or chart */}
) : (
Failed to load statistics
)} ); }