# تهيئة القوائم لتخزين السجلات
income_records = []
expense_records = []
TAX_RATE = 0.15 # 15% ضريبة

# --- الدوال الرئيسية ---

def display_menu():
    """تعرض قائمة الخيارات للمستخدم."""
    print("\nWelcome to the Budget Management Application!")
    print("Please choose an option:")
    print("1. Add income")
    print("2. Add expense")
    print("3. View summary")
    print("4. Exit")

def add_transaction(transaction_list, type_name):
    """دالة عامة لإضافة الدخل أو المصروفات."""
    print(f"\nEnter your choice: {1 if type_name == 'income' else 2}")
    
    # إدخال الوصف
    description = input(f"Enter {type_name} description: ")
    
    # إدخال المبلغ مع التحقق من النوع
    while True:
        try:
            amount_str = input(f"Enter {type_name} amount: ")
            amount = float(amount_str)
            if amount <= 0:
                print("Amount must be a positive number. Please try again.")
                continue
            break
        except ValueError:
            print("Invalid input. Please enter a numerical amount.")
    
    # إضافة السجل إلى القائمة المناسبة
    transaction_list.append({'description': description, 'amount': amount})
    print(f"{type_name.capitalize()} added!")

def view_summary():
    """تحسب وتعرض الملخص المالي."""
    
    # حساب الإجمالي
    total_income = sum(item['amount'] for item in income_records)
    total_expenses = sum(item['amount'] for item in expense_records)
    
    # حساب صافي الربح والضريبة
    net_profit = total_income - total_expenses
    tax_to_be_paid = net_profit * TAX_RATE if net_profit > 0 else 0
    
    # عرض النتائج كما في الصورة
    print("\nEnter your choice: 3")
    print("Summary:")
    print(f"Total income: ${total_income:,.2f}")
    print(f"Total expenses: ${total_expenses:,.2f}")
    print(f"Net profit: ${net_profit:,.2f}")
    print(f"Tax to be paid: ${tax_to_be_paid:,.2f}")

# --- الحلقة الرئيسية للتطبيق (Main Loop) ---

def main():
    """الحلقة الرئيسية التي تدير تشغيل التطبيق."""
    while True:
        display_menu()
        
        # قراءة خيار المستخدم
        choice = input("\nEnter your choice: ")
        
        if choice == '1':
            # إضافة دخل
            add_transaction(income_records, "income")
        
        elif choice == '2':
            # إضافة مصروف
            add_transaction(expense_records, "expense")
        
        elif choice == '3':
            # عرض الملخص
            view_summary()
        
        elif choice == '4':
            # الخروج من التطبيق
            print("\nEnter your choice: 4")
            print("Exiting the application. Goodbye!")
            break
        
        else:
            # خيار غير صالح
            print("Invalid choice. Please select a number between 1 and 4.")

# تشغيل الدالة الرئيسية
if __name__ == "__main__":
    main()