mirrored_repositories/Expenses_Tracker_App/lib/screens/home
import 'dart:math';
import 'package:expense_repository/expense_repository.dart';
import 'package:expenses_tracker/screens/home/widgets/income_widget.dart';
import 'package:expenses_tracker/utils/constants/colors.dart';
import 'package:expenses_tracker/utils/constants/sizes.dart';
import 'package:expenses_tracker/utils/constants/tr_text.dart';
import 'package:expenses_tracker/utils/helpers/helpers.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class MainCard extends StatelessWidget {
  final List<Expense> expenses;
  const MainCard(this.expenses, {super.key});
  @override
  Widget build(BuildContext context) {
    final dark = EHelperFunctions.isDarkMode(context);

    // USD
    double totalIncomeUSD =
        EHelperFunctions.calculateTotalIncomeByCurrency(expenses, '\$');
    double totalExpenseUSD =
        EHelperFunctions.calculateTotalExpenseByCurrency(expenses, '\$');
    double totalBalanceUSD = totalIncomeUSD - totalExpenseUSD;

    // EURO
    double totalIncomeEURO =
        EHelperFunctions.calculateTotalIncomeByCurrency(expenses, '€');
    double totalExpenseEURO =
        EHelperFunctions.calculateTotalExpenseByCurrency(expenses, '€');
    double totalBalanceEURO = totalIncomeEURO - totalExpenseEURO;

    // POUND
    double totalIncomePound =
        EHelperFunctions.calculateTotalIncomeByCurrency(expenses, '£');
    double totalExpensePound =
        EHelperFunctions.calculateTotalExpenseByCurrency(expenses, '£');
    double totalBalancePound = totalIncomePound - totalExpensePound;

    // XAU (ALTIN)
    double totalIncomeXAU =
        EHelperFunctions.calculateTotalIncomeByCurrency(expenses, 'XAU');
    double totalExpenseXAU =
        EHelperFunctions.calculateTotalExpenseByCurrency(expenses, 'XAU');
    double totalBalanceXAU = totalIncomeXAU - totalExpenseXAU;

    // TL
    double totalIncomes =
        EHelperFunctions.calculateTotalIncomeByCurrency(expenses, '₺');
    double totalExpenses =
        EHelperFunctions.calculateTotalExpenseByCurrency(expenses, '₺');
    double totalBalance =
        EHelperFunctions.calculateTotalBalance(totalIncomes, totalExpenses);

    return Container(
      width: MediaQuery.of(context).size.width,
      height: MediaQuery.of(context).size.width / 2,
      decoration: BoxDecoration(
          gradient: const LinearGradient(colors: [
            EColors.primary,
            EColors.secondary,
            EColors.tertiary,
          ], transform: GradientRotation(pi / 4)),
          borderRadius: BorderRadius.circular(ESizes.borderRadiusXxl),
          boxShadow: [
            BoxShadow(
                blurRadius: 4,
                color: dark ? EColors.darkerGrey : EColors.grey,
                offset: const Offset(5, 5))
          ]),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          const SizedBox(height: ESizes.md),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              Text(ETexts.totalBalance,
                  style: Theme.of(context)
                      .textTheme
                      .headlineMedium!
                      .apply(color: EColors.textWhite)),
              Text('$totalBalance',
                  style: Theme.of(context)
                      .textTheme
                      .headlineLarge!
                      .apply(color: EColors.textWhite)),
            ],
          ),
          Padding(
            padding: const EdgeInsets.only(
                top: ESizes.md,
                bottom: ESizes.sm,
                right: ESizes.sm,
                left: ESizes.sm),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    IncomeWidget(
                      icon: CupertinoIcons.arrow_up,
                      title: ETexts.income,
                      money: '$totalIncomes',
                    ),
                    const SizedBox(height: ESizes.sm),
                    IncomeWidget(
                      icon: CupertinoIcons.arrow_down,
                      title: ETexts.expenses,
                      money: '$totalExpenses',
                    )
                  ],
                ),
                const SizedBox(width: ESizes.md),
                Column(
                  children: [
                    IncomeWidget(
                      icon: CupertinoIcons.money_dollar,
                      title: ETexts.dollar,
                      money: '$totalBalanceUSD',
                    ),
                    const SizedBox(height: ESizes.sm),
                    IncomeWidget(
                      icon: CupertinoIcons.money_euro,
                      title: ETexts.euro,
                      money: '$totalBalanceEURO',
                    ),
                  ],
                ),
                const SizedBox(width: ESizes.md),
                Column(
                  children: [
                    IncomeWidget(
                      icon: Icons.circle,
                      title: ETexts.xau,
                      money: '$totalBalanceXAU',
                    ),
                    const SizedBox(height: ESizes.sm),
                    IncomeWidget(
                      icon: Icons.currency_pound_outlined,
                      title: ETexts.pound,
                      money: '$totalBalancePound',
                    )
                  ],
                ),
              ],
            ),
          )
        ],
      ),
    );
  }
}
