"use client"; import { useState } from "react"; import { Table, TableBody, TableCaption, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { DashboardCard } from "@/components/dashboard-card"; import { ArrowRightIcon, ArrowUpIcon } from "@/components/ui/phosphor-icons"; import { cn } from "@/lib/utils"; import type { HouseholdRow } from "@/lib/poverty-types"; const PREVIEW_COUNT = 5; function PovertyBadge({ level }: { level: string }) { if (level === "Extreme") { return ( Ekstrem ); } if (level === "Miskin") { return ( Miskin ); } return ( Rentan ); } function FuzzyPriorityBadge({ label }: { label: string | null }) { if (!label) return ; const colors: Record = { "SANGAT TINGGI": "bg-red-100 text-red-700 border-red-200", "TINGGI": "bg-orange-100 text-orange-700 border-orange-200", "SEDANG": "bg-amber-100 text-amber-700 border-amber-200", "RENDAH": "bg-emerald-100 text-emerald-700 border-emerald-200", "TIDAK PRIORITAS": "bg-blue-100 text-blue-700 border-blue-200", }; return ( {label} ); } function ScoreBar({ value }: { value: number }) { const pct = Math.round((value / 10) * 100); const color = value <= 3 ? "bg-red-400" : value <= 6 ? "bg-amber-400" : "bg-emerald-400"; return (
{value}/10
); } export function PovertyHouseholdsTable({ rows, loading = false, }: { rows: HouseholdRow[]; loading?: boolean; }) { const [showAll, setShowAll] = useState(false); const visible = showAll ? rows : rows.slice(0, PREVIEW_COUNT); const hasMore = rows.length > PREVIEW_COUNT; return ( Data Warga Miskin {loading ? "Memuat data…" : `${rows.length} entri tersimpan dari peta · skor prioritas fuzzy`} {loading && (
Memuat data...
)} {!loading && rows.length === 0 && (
Belum ada data. Tambah marker di peta untuk mencatat warga miskin.
)} {!loading && rows.length > 0 && ( Data warga miskin dengan skor prioritas fuzzy. # Kepala Keluarga Jiwa Rumah Aset Tingkat Penghasilan Skor Fuzzy Prioritas {visible.map((row, i) => ( {i + 1} {row.head_name} {row.family_count} Rp {Number(row.penghasilan).toLocaleString("id-ID")} {row.fuzzy_score != null ? Number(row.fuzzy_score).toFixed(1) : "—"} ))}
)}
{/* View All overlay — only when collapsed and there are hidden rows */} {!showAll && hasMore && (
)} {/* Collapse button — only when expanded */} {showAll && rows.length > PREVIEW_COUNT && (
)}
); }