import { AlertCircle, ArrowDownRight, ArrowUpRight, CheckSquare, Receipt, Users, Wallet, } from "lucide-react"; import { Card, CardContent } from "@/components/ui/card"; import { formatTRY } from "@/lib/format"; import { cn } from "@/lib/utils"; import type { DashboardData } from "@/lib/appwrite/dashboard-queries"; function delta(current: number, previous: number): { pct: number; positive: boolean } | null { if (previous === 0) { if (current === 0) return null; return { pct: 100, positive: true }; } const pct = ((current - previous) / previous) * 100; return { pct: Math.abs(pct), positive: pct >= 0 }; } export function Metrics({ data }: { data: DashboardData["metrics"] }) { const incomeDelta = delta(data.monthIncome, data.prevMonthIncome); const cards = [ { label: "Müşteriler", value: String(data.totalCustomers), sub: `${data.activeCustomers} aktif`, icon: Users, tone: "default", }, { label: "Bu ayki gelir", value: formatTRY(data.monthIncome), sub: incomeDelta ? `${incomeDelta.positive ? "+" : "−"}${incomeDelta.pct.toFixed(1)}% önceki ay` : "Geçen ay veri yok", icon: Wallet, tone: "income", trend: incomeDelta, }, { label: "Bekleyen tahsilat", value: formatTRY(data.outstanding), sub: data.overdueCount > 0 ? `${data.overdueCount} vadesi geçmiş` : "Vadesi geçmiş yok", icon: Receipt, tone: data.overdueCount > 0 ? "warning" : "default", }, { label: "Açık görevler", value: String(data.openTasks), sub: data.urgentTasks > 0 ? `${data.urgentTasks} acil` : "Acil görev yok", icon: CheckSquare, tone: data.urgentTasks > 0 ? "warning" : "default", }, ]; const toneClass: Record = { default: "text-muted-foreground", income: "text-emerald-600 dark:text-emerald-400", warning: "text-amber-600 dark:text-amber-400", }; return (
{cards.map((c) => { const Icon = c.icon; return (

{c.label}

{c.value}

0 ? "text-amber-600 dark:text-amber-400" : "text-muted-foreground", )} > {c.trend && (c.trend.positive ? ( ) : ( ))} {c.tone === "warning" && data.overdueCount + data.urgentTasks > 0 && ( )} {c.sub}

); })}
); }