import 'package:drift/drift.dart' show Value; import 'package:flutter/material.dart'; import '../database/daos/month_dao.dart'; import '../database/database.dart'; import '../theme.dart'; import 'inline_edit_cell.dart'; class LuxuryCard extends StatelessWidget { final int remainingCents; final int eatingOutBudgetCents; final int miscTotalCents; final MonthDao monthDao; final int monthPlanId; final VoidCallback onDataChanged; const LuxuryCard({ super.key, required this.remainingCents, required this.eatingOutBudgetCents, required this.miscTotalCents, required this.monthDao, required this.monthPlanId, required this.onDataChanged, }); @override Widget build(BuildContext context) { final spentCents = eatingOutBudgetCents + miscTotalCents; final leftCents = remainingCents - spentCents; final progress = remainingCents > 0 ? (spentCents / remainingCents).clamp(0.0, 1.0) : 0.0; return Container( decoration: BoxDecoration( color: bgCard, border: Border.all(color: borderColor), borderRadius: BorderRadius.circular(6), ), clipBehavior: Clip.antiAlias, child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ Container( padding: const EdgeInsets.symmetric(horizontal: cardPadding, vertical: 8), decoration: const BoxDecoration(border: Border(bottom: BorderSide(color: dividerColor))), child: Row( children: [ const Text('LUXURY ALLOWANCE', style: TextStyle(fontSize: labelSize, color: textMuted, letterSpacing: 0.5)), const Spacer(), Text( '${formatCents(leftCents)} left', style: TextStyle(fontSize: labelSize, fontFamily: monoFont, color: leftCents >= 0 ? accentAmber : accentRed), ), ], ), ), Padding( padding: const EdgeInsets.all(cardPadding), child: Column( children: [ // Progress bar Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text('Spent: ${formatCents(spentCents)}', style: const TextStyle(fontSize: labelSize, color: textMuted)), Text('Budget: ${formatCents(remainingCents)}', style: const TextStyle(fontSize: labelSize, color: textMuted)), ], ), const SizedBox(height: 4), ClipRRect( borderRadius: BorderRadius.circular(3), child: LinearProgressIndicator( value: progress, minHeight: 6, backgroundColor: borderColor, valueColor: AlwaysStoppedAnimation( progress > 0.8 ? accentRed : accentGreen, ), ), ), const SizedBox(height: 8), // Eating out (editable amount) Padding( padding: const EdgeInsets.symmetric(vertical: 2), child: Row( children: [ const Text('Eating out', style: TextStyle(fontSize: bodySize, color: textMuted)), const Spacer(), SizedBox( width: 80, child: InlineEditCell.cents( cents: eatingOutBudgetCents, onSaved: (cents) async { await monthDao.updateMonthPlan( monthPlanId, MonthPlansCompanion(eatingOutBudgetCents: Value(cents)), ); onDataChanged(); }, style: const TextStyle(fontSize: bodySize, fontFamily: monoFont, color: textMuted), ), ), ], ), ), // Misc total (read-only, sum from misc items) _luxuryItem('Misc spend', miscTotalCents), ], ), ), ], ), ); } Widget _luxuryItem(String label, int cents) { return Padding( padding: const EdgeInsets.symmetric(vertical: 2), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text(label, style: const TextStyle(fontSize: bodySize, color: textMuted)), Text(formatCents(cents), style: const TextStyle(fontSize: bodySize, fontFamily: monoFont, color: textMuted)), ], ), ); } }