import { cookies } from 'next/headers' import { redirect } from 'next/navigation' import { supabase } from '@/lib/supabase' import { LogoutButton } from '@/components/logout-button' import { ArrowLeft } from 'lucide-react' import Link from 'next/link' import { StuntingChart } from './StuntingChart' const START_YEAR = 2026 export default async function TrendStuntingPage() { const cookieStore = await cookies() const sessionCookie = cookieStore.get('user_session') if (!sessionCookie) redirect('/') const session = JSON.parse(sessionCookie.value) if (session.role !== 'admin') redirect('/dashboard') // Fetch all stunting data (only needed columns) const { data: rawData, error } = await supabase .from('hasil_stunting_balita') .select('status_stunting, tanggal_upload, nama_posyandu') .not('tanggal_upload', 'is', null) .order('tanggal_upload', { ascending: true }) if (error) { return (
Gagal memuat data stunting.
) } // Build year list: always include from START_YEAR up to current year, // plus any years found in real data beyond that range const currentYear = new Date().getFullYear() const dataYears = Array.from( new Set((rawData ?? []).map(d => new Date(d.tanggal_upload).getFullYear())) ) const allYears = Array.from( new Set([ ...Array.from({ length: Math.max(currentYear, ...dataYears) - START_YEAR + 1 }, (_, i) => START_YEAR + i), ...dataYears, ]) ).filter(y => y >= START_YEAR).sort((a, b) => a - b) return (
{/* Header */}
Kembali

Trend Stunting Daerah

ANALISIS DATA SEMUA POSYANDU

{/* Page Card */}
{/* Chart Component (Client) */}
) }