import 'dart:io'; void main() { List> incomeList = []; List> expenseList = []; print('مرحبًا بك في تطبيق إدارة الميزانية!'); while (true) { print('\n====== القائمة ======'); print('1. إضافة دخل'); print('2. إضافة مصروف'); print('3. عرض الملخص'); print('4. خروج'); stdout.write('اختر خيارك (1-4): '); String? choice = stdin.readLineSync(); switch (choice) { case '1': _addEntry(incomeList, isIncome: true); break; case '2': _addEntry(expenseList, isIncome: false); break; case '3': _showSummary(incomeList, expenseList); break; case '4': print('وداعاً!'); return; default: print('خيار غير صحيح.'); } } } void _addEntry(List> list, {required bool isIncome}) { stdout.write('أدخل الوصف: '); String? desc = stdin.readLineSync(); if (desc == null || desc.isEmpty) { print('الوصف لا يمكن أن يكون فارغًا.'); return; } stdout.write('أدخل المبلغ: '); String? amt = stdin.readLineSync(); double? amount = double.tryParse(amt ?? ''); if (amount == null || amount <= 0) { print('الرجاء إدخال مبلغ موجب.'); return; } list.add({desc: amount}); print('${isIncome ? "تم إضافة دخل" : "تم إضافة مصروف"}: $desc - $amount'); } void _showSummary(List> incomes, List> expenses) { double totalIncome = 0, totalExpense = 0; for (var m in incomes) { for (var v in m.values) totalIncome += v; } for (var m in expenses) { for (var v in m.values) totalExpense += v; } double net = totalIncome - totalExpense; print('\n--- ملخص ---'); print('إجمالي الدخل: $totalIncome'); print('إجمالي المصروفات: $totalExpense'); if (net > 0) { print('الربح الصافي: $net'); double tax = net * 0.15; print('الضريبة (15%): $tax'); print('صافي الربح بعد الضريبة: ${net - tax}'); } else if (net < 0) { print('الخسارة: ${net.abs()}'); } else { print('لا ربح ولا خسارة.'); } }