import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; bool run = true; print('تطبيق إدارة الميزانية'); print('----------------------'); while (run) { print('\nاختر العملية:'); print('1. إضافة دخل'); print('2. إضافة مصروف'); print('3. عرض الملخص'); print('4. خروج'); stdout.write('اختيارك: '); String? choice = stdin.readLineSync(); if (choice == '1') { stdout.write('وصف الدخل: '); String? desc = stdin.readLineSync(); stdout.write('قيمة الدخل: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); if (amount != null && amount > 0) { incomeList.add({desc ?? 'دخل': amount}); print('تمت إضافة الدخل.'); } else { print('قيمة غير صحيحة.'); } } else if (choice == '2') { stdout.write('وصف المصروف: '); String? desc = stdin.readLineSync(); stdout.write('قيمة المصروف: '); String? amountInput = stdin.readLineSync(); double? amount = double.tryParse(amountInput ?? ''); 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; print('\n--- ملخص الميزانية ---'); print('إجمالي الدخل: $totalIncome'); print('إجمالي المصروفات: $totalExpense'); if (net >= 0) { print('الربح الصافي: $net'); double tax = net > 0 ? net * 0.15 : 0; if (tax > 0) print('الضريبة المستحقة: $tax'); } else { print('الخسارة الصافية: ${net.abs()}'); } } else if (choice == '4') { print('تم إغلاق البرنامج.'); run = false; } else { print('خيار غير صحيح.'); } } }