diff --git a/src/screens/DashboardScreen.tsx b/src/screens/DashboardScreen.tsx index ef93ac2..f15fcf5 100644 --- a/src/screens/DashboardScreen.tsx +++ b/src/screens/DashboardScreen.tsx @@ -224,6 +224,33 @@ export function DashboardScreen() { } } + const hasTodayActivity = today.income > 0 || today.expense > 0; + const monthNet = monthIncome - monthExpense; + + // Nyawa keuangan (health bar) + const hpPct = + avgDailyExpense > 0 + ? Math.min(100, Math.round(((coverageDays ?? 0) / remainingDays) * 100)) + : 100; + let hpStatus = 'SEHAT'; + let hpColor = '#16A34A'; + let hpBarColor = '#22C55E'; + let hpMsg = + avgDailyExpense > 0 + ? `Nyawa aman — saldo cukup ${coverageDays} hari (sisa ${remainingDays}) 🛡️` + : 'Belum ada pengeluaran bulan ini — nyawa penuh! 😎'; + if (avgDailyExpense > 0 && hpPct < 40) { + hpStatus = 'KRITIS'; + hpColor = '#DC2626'; + hpBarColor = '#EF4444'; + hpMsg = `Saldo cukup ${coverageDays} dari ${remainingDays} hari — kurangi belanja! 🚨`; + } else if (avgDailyExpense > 0 && hpPct < 75) { + hpStatus = 'WASPADA'; + hpColor = '#D97706'; + hpBarColor = '#F59E0B'; + hpMsg = `Saldo cukup ${coverageDays} dari ${remainingDays} hari — jaga pengeluaran ⚔️`; + } + // Bar HP: width bergerak halus mengikuti data useEffect(() => { Animated.timing(hpAnim, { @@ -271,33 +298,6 @@ export function DashboardScreen() { return () => loop?.stop(); }, [hpPct, pulse]); - const hasTodayActivity = today.income > 0 || today.expense > 0; - const monthNet = monthIncome - monthExpense; - - // Nyawa keuangan (health bar) - const hpPct = - avgDailyExpense > 0 - ? Math.min(100, Math.round(((coverageDays ?? 0) / remainingDays) * 100)) - : 100; - let hpStatus = 'SEHAT'; - let hpColor = '#16A34A'; - let hpBarColor = '#22C55E'; - let hpMsg = - avgDailyExpense > 0 - ? `Nyawa aman — saldo cukup ${coverageDays} hari (sisa ${remainingDays}) 🛡️` - : 'Belum ada pengeluaran bulan ini — nyawa penuh! 😎'; - if (avgDailyExpense > 0 && hpPct < 40) { - hpStatus = 'KRITIS'; - hpColor = '#DC2626'; - hpBarColor = '#EF4444'; - hpMsg = `Saldo cukup ${coverageDays} dari ${remainingDays} hari — kurangi belanja! 🚨`; - } else if (avgDailyExpense > 0 && hpPct < 75) { - hpStatus = 'WASPADA'; - hpColor = '#D97706'; - hpBarColor = '#F59E0B'; - hpMsg = `Saldo cukup ${coverageDays} dari ${remainingDays} hari — jaga pengeluaran ⚔️`; - } - return (