import type { ReactElement, ReactNode } from 'react' import { Card, CardContent } from '@cfdm/ui/components/card' import { cn } from '@cfdm/ui/lib/utils' import { TruncatedText } from '@/components/truncated-text' export interface SectionCardItem { label: ReactNode value: string | number | ReactElement hint?: ReactNode icon?: ReactNode badge?: ReactNode variant?: 'default' | 'warning' | 'destructive' active?: boolean onClick?: () => void } const VARIANT_CLASS: Record, string> = { default: '', warning: 'border-warning/50', destructive: 'border-destructive/50', } function sectionGridClass(count: number): string { if (count <= 1) return 'grid-cols-1' if (count === 2) return 'sm:grid-cols-2' if (count === 3) return 'sm:grid-cols-2 lg:grid-cols-3' if (count === 4) return 'sm:grid-cols-2 lg:grid-cols-4' if (count === 5) return 'sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-5' return 'sm:grid-cols-2 lg:grid-cols-3' } export function SectionCards({ items, className }: { items: SectionCardItem[]; className?: string }) { return (
{items.map((item, idx) => { const clickable = Boolean(item.onClick) const content = ( {item.icon ? ( {item.icon} ) : null}
{typeof item.label === 'string' ? ( {item.label} ) : ( {item.label} )} {item.badge ? {item.badge} : null}
{item.value} {item.hint ? ( typeof item.hint === 'string' ? ( · {item.hint} ) : ( · {item.hint} ) ) : null}
) return ( { if (e.key === 'Enter' || e.key === ' ') { e.preventDefault() item.onClick?.() } } : undefined } > {content} ) })}
) }