import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; const double taxRate = 0.15; print('مرحباً بك في تطبيق إدارة الميزانية'); while (true) { print('\n=== Budget Menu ==='); print('1. إضافة دخل'); print('2. إضافة مصروف'); print('3. عرض الملخص'); print('4. خروج'); stdout.write('اختر خيارك: '); String? choice = stdin.readLineSync(); if (choice == null) { print('إدخال غير صالح، حاول مرة أخرى.'); continue; } if (choice.trim() == '1') { stdout.write('ادخل وصف الدخل: '); String? desc = stdin.readLineSync(); if (desc == null || desc.trim().isEmpty) { print('الوصف لا يمكن أن يكون فارغاً.'); continue; } stdout.write('ادخل المبلغ: '); String? amtStr = stdin.readLineSync(); double? amt = (amtStr == null) ? null : double.tryParse(amtStr.trim()); if (amt == null || amt <= 0) { print('الرجاء إدخال مبلغ موجب صحيح.'); continue; } incomeList.add({desc.trim(): amt}); print('تمت إضافة دخل: ${desc.trim()} — $amt'); } else if (choice.trim() == '2') { stdout.write('ادخل وصف المصروف: '); String? desc = stdin.readLineSync(); if (desc == null || desc.trim().isEmpty) { print('الوصف لا يمكن أن يكون فارغاً.'); continue; } stdout.write('ادخل المبلغ: '); String? amtStr = stdin.readLineSync(); double? amt = (amtStr == null) ? null : double.tryParse(amtStr.trim()); if (amt == null || amt <= 0) { print('الرجاء إدخال مبلغ موجب صحيح.'); continue; } expenseList.add({desc.trim(): amt}); print('تمت إضافة مصروف: ${desc.trim()} — $amt'); } else if (choice.trim() == '3') { double totalIncome = 0.0; double totalExpense = 0.0; for (var entry in incomeList) { // كل entry هو خريطة واحدة مع مفتاح الوصف وقيمة المبلغ entry.forEach((k, v) => totalIncome += v); } for (var entry in expenseList) { entry.forEach((k, v) => totalExpense += v); } double netProfit = totalIncome - totalExpense; print('\n--- الملخص ---'); print('إجمالي الدخل: \$${totalIncome.toStringAsFixed(2)}'); print('إجمالي المصروفات: \$${totalExpense.toStringAsFixed(2)}'); if (netProfit > 0) { print('Your net profit is \$${netProfit.toStringAsFixed(2)}'); // ضريبة 15% (اختياري حسب المتطلبات) double tax = netProfit * taxRate; print('Tax to pay (15%): \$${tax.toStringAsFixed(2)}'); print('Net after tax: \$${(netProfit - tax).toStringAsFixed(2)}'); } else if (netProfit < 0) { print('Your net loss is \$${(netProfit.abs()).toStringAsFixed(2)}'); } else { print('Break-even: no profit, no loss.'); } } else if (choice.trim() == '4') { print('خروج — إلى اللقاء!'); return; } else { print('خيار غير معروف، حاول مرة أخرى.'); } } }