import { Card, CardContent } from "@suphark/ui/components/ui/card"; import { cn } from "@suphark/ui/lib/utils"; import { Minus, TrendingDown, TrendingUp } from "lucide-react"; import type { ReactNode } from "react"; /** `danger`/`neutral` = ชื่อเดียวกับ `destructive`/`default` (ให้ตรงกับ StatusBadge/Notice/Banner) */ export type StatTone = | "default" | "success" | "warning" | "destructive" | "info" | "danger" | "neutral"; const TONE_TEXT: Record = { default: "text-foreground", success: "text-success", // text-warning (เหลือง) บนพื้นขาว 1.57:1 อ่านไม่ออก — ตัวหนังสือใช้โทนเข้มของ warning warning: "text-warning-muted-foreground", destructive: "text-destructive", info: "text-info", neutral: "text-foreground", danger: "text-destructive", }; const TONE_ICON: Record = { default: "bg-muted text-muted-foreground", success: "bg-success-subtle text-success-subtle-foreground", warning: "bg-warning-subtle text-warning-subtle-foreground", destructive: "bg-destructive-subtle text-destructive-subtle-foreground", info: "bg-info-subtle text-info-subtle-foreground", neutral: "bg-muted text-muted-foreground", danger: "bg-destructive-subtle text-destructive-subtle-foreground", }; export interface StatDelta { /** ข้อความที่แสดง เช่น "+12%" หรือ "+3 สัปดาห์นี้" */ value: ReactNode; /** ขึ้น = ดี/ไม่ดี ต่างกันไปตามตัวชี้วัด → แอปบอกโทนเอง (ค่าเริ่มต้นดูจาก direction) */ direction?: "up" | "down" | "flat"; tone?: StatTone; /** ข้อความเทียบ เช่น "จากเดือนก่อน" */ hint?: ReactNode; } const DELTA_ICON = { up: TrendingUp, down: TrendingDown, flat: Minus }; /** * ตัวเลขสรุปบนหน้าภาพรวม/สุขภาพระบบ — เพิ่มไอคอน, ป้าย และส่วนต่างจากช่วงก่อนได้ * (Pi Auth มี 17 การ์ดแบบนี้, DueBell มี DeltaBadge ของตัวเอง) */ export function Stat({ label, value, hint, icon, badge, delta, tone = "default", className, }: { label: ReactNode; value: ReactNode; hint?: ReactNode; /** ไอคอนมุมขวาบน (ใส่กรอบพื้นตาม `tone` ให้) */ icon?: ReactNode; /** ป้ายท้ายป้ายชื่อ เช่น `` */ badge?: ReactNode; /** ส่วนต่างจากช่วงก่อน */ delta?: StatDelta; /** โทนของตัวเลขและไอคอน */ tone?: StatTone; className?: string; }) { const direction = delta?.direction ?? "flat"; const DeltaIcon = DELTA_ICON[direction]; const deltaTone = delta?.tone ?? (direction === "up" ? "success" : direction === "down" ? "destructive" : "default"); return (
{label} {badge} {value} {delta && ( {delta.hint && {delta.hint}} )} {hint && {hint}}
{icon && ( )}
); } /** กริดของ `Stat` — คอลัมน์ตามจำนวนที่ต้องการ (ค่าเริ่มต้น 1 → 2 → 4 ตามความกว้างจอ) */ export function StatGrid({ children, columns = 4, className, }: { children: ReactNode; columns?: 2 | 3 | 4; className?: string; }) { return (
{children}
); }