import Alert from '@/components/Alert'; import Card from '@/components/Card'; import { formatNumber } from '@/lib/helper'; import { DashboardStatisticsData } from '@/types/api/dashboard/dashboard'; import { Icon } from '@iconify/react'; interface DashboardStatsProps { data: DashboardStatisticsData[]; } // Konfigurasi untuk setiap kartu const CARD_CONFIG = [ { key: 'HPP Global', icon: 'heroicons:banknotes', alertColor: 'warning' as const, suffix: ' /Kg', prefix: 'RP ', }, { key: 'Avg. Selling Price', icon: 'heroicons:document-currency-dollar', alertColor: 'success' as const, suffix: ' /Kg Telur', prefix: '', }, { key: 'FCR', icon: 'heroicons:clipboard-document-list', alertColor: 'info' as const, suffix: '', prefix: '', }, { key: 'Mortality', icon: 'heroicons:exclamation-triangle', alertColor: 'error' as const, suffix: ' %', prefix: '', }, ]; const DashboardStats = ({ data }: DashboardStatsProps) => { // Helper to get trend icon and color const getTrendDisplay = (percent: number) => { const isPositive = percent >= 0; return { icon: isPositive ? 'heroicons:arrow-trending-up' : 'heroicons:arrow-trending-down', color: isPositive ? 'text-[#008000]' : 'text-[#FF3A3A]', value: Math.abs(percent), }; }; // Helper to format value const formatValue = (value: number, prefix: string, suffix: string) => { return ( <> {prefix} {formatNumber(value)} {suffix && ( {suffix} )} ); }; return (
{CARD_CONFIG.map((config) => { // Find matching data from API const cardData = data.find((item) => item.label === config.key); if (!cardData) { // Show placeholder card for missing data (FCR & Mortality) return (
From last month
Filter Required
} >

{config.key}

********

); } const trend = getTrendDisplay(cardData.percent_last_month); return (
From last month
{trend.value}%
} >

{cardData.label}

{formatValue(cardData.value, config.prefix, config.suffix)}

); })} ); }; export default DashboardStats;