import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; while (true) { print('\n===== Budget Manager ====='); print('1. إضافة دخل'); print('2. إضافة مصروف'); print('3. عرض الملخص'); print('4. خروج'); stdout.write('اختر: '); String? choice = stdin.readLineSync(); if (choice == '1') { stdout.write('وصف الدخل: '); String desc = (stdin.readLineSync() ?? '').trim(); stdout.write('المبلغ: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount >= 0) { incomeList.add({desc: amount}); print('تمت الإضافة.'); } else { print('مبلغ غير صحيح.'); } } else if (choice == '2') { stdout.write('وصف المصروف: '); String desc = (stdin.readLineSync() ?? '').trim(); stdout.write('المبلغ: '); double? amount = double.tryParse(stdin.readLineSync() ?? ''); if (amount != null && amount >= 0) { expenseList.add({desc: amount}); print('تمت الإضافة.'); } else { print('مبلغ غير صحيح.'); } } else if (choice == '3') { double totalIncome = 0; double totalExpense = 0; for (var i in incomeList) totalIncome += i.values.first; for (var e in expenseList) totalExpense += e.values.first; double net = totalIncome - totalExpense; double tax = net > 0 ? net * 0.15 : 0; print('\n--- الملخص ---'); print('إجمالي الدخل: \$${totalIncome.toStringAsFixed(2)}'); print('إجمالي المصروف: \$${totalExpense.toStringAsFixed(2)}'); if (net > 0) { print('الربح الصافي: \$${net.toStringAsFixed(2)}'); print('الضريبة (15%): \$${tax.toStringAsFixed(2)}'); } else if (net < 0) { print('الخسارة: \$${net.abs().toStringAsFixed(2)}'); } else { print('لا يوجد ربح أو خسارة.'); } } else if (choice == '4') { print('تم إغلاق البرنامج.'); break; } else { print('خيار خاطئ.'); } } }