import 'dart:developer';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gap/gap.dart';

import '../../../../../core/routes/route_name.dart';
import '../../../../../core/routes/routes.dart';
import '../../../../../core/styles/app_color.dart';
import '../../../../../core/styles/app_images.dart';
import '../../../../../core/styles/app_text.dart';
import '../../../../../shared/components/text_widget.dart';

class WalletListSection extends StatelessWidget {
  const WalletListSection({super.key});

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child: ListView.builder(
        shrinkWrap: true,
        itemCount: data.length,
        itemBuilder: (context, index) {
          return Padding(
            padding: const EdgeInsets.only(bottom: 10.0),
            child: GestureDetector(
              onTap: () {
                goRouter.pushNamed(RouteName.walletDetails, pathParameters: {
                  "type": data[index]['title'],
                });
              },
              child: Container(
                height: 90.h,
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(22.r),
                  color: AppColor.fillColor,
                ),
                child: Padding(
                  padding: const EdgeInsets.all(12.0),
                  child: Row(
                    children: [
                      getIcon(data[index]['title']),
                      SizedBox(width: 12.w),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          TextWidget().text14W700(
                            data[index]['title'],
                            clr: AppColor.otpTextColor,
                          ),
                          Gap(4.h),
                          (data[index]['subTitle'] != '')
                              ? Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    TextWidget().text12W400(
                                      data[index]['subTitle'],
                                      clr: AppColor.otpTextColor,
                                    ),
                                    Gap(4.h),
                                  ],
                                )
                              : const SizedBox(),
                          TextWidget().text11W500(data[index]['dateTime'],
                              clr: AppColor.hintTextColor)
                        ],
                      ),
                      const Spacer(),
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.end,
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          (data[index]['onHold'])
                              ? Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    TextWidget().text14W700(AppText.onHold,
                                        clr: AppColor.onHoldTextColor),
                                    Gap(4.h),
                                  ],
                                )
                              : const SizedBox(),
                          TextWidget().text14W700(data[index]['value'],
                              clr: AppColor.otpTextColor),
                          Gap(4.h),
                          (data[index]['subValue'] != '')
                              ? TextWidget().text12W500(data[index]['subValue'],
                                  clr: AppColor.otpTextColor)
                              : const SizedBox(),
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ),
          );
        },
      ),
    );
  }
}

Widget getIcon(String title) {
  log(title);
  if (title == 'Deposit') {
    return Container(
      decoration: const BoxDecoration(
          shape: BoxShape.circle, color: AppColor.depositListIconColor),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Image.asset(
          AppImages.depositListIcon,
          height: 25.h,
        ),
      ),
    );
  } else if (title == 'Withdrawal') {
    return Container(
      decoration: const BoxDecoration(
          shape: BoxShape.circle, color: AppColor.withdrawalListIconColor),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Image.asset(AppImages.withdrawalListIcon, height: 25.h),
      ),
    );
  } else if (title == 'Investment' || title == 'confirm-investment') {
    return Container(
      decoration: const BoxDecoration(
          shape: BoxShape.circle, color: AppColor.investmentListIconColor),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Image.asset(AppImages.investmentListIcon, height: 25.h),
      ),
    );
  } else if (title == 'Yield') {
    return Container(
      decoration: const BoxDecoration(
          shape: BoxShape.circle, color: AppColor.yieldListIconColor),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Image.asset(AppImages.yieldListIcon, height: 25.h),
      ),
    );
  } else {
    return Container(
      decoration: const BoxDecoration(
          shape: BoxShape.circle, color: AppColor.refundListIconColor),
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: Image.asset(AppImages.refundListIcon, height: 25.h),
      ),
    );
  }
}

List data = [
  {
    'title': AppText.deposit,
    'subTitle': '',
    'dateTime': '10/04/2024 22:04',
    'value': '+ SAR 100,000',
    'subValue': '',
    'onHold': false,
  },
  {
    'title': AppText.withdrawal,
    'subTitle': '',
    'dateTime': '10/04/2024 22:04',
    'value': '- SAR 100,000',
    'subValue': '',
    'onHold': true,
  },
  {
    'title': AppText.investment,
    'subTitle': 'Name of Investment',
    'dateTime': '10/04/2024 22:04',
    'value': '- SAR 100,000',
    'subValue': '',
    'onHold': false,
  },
  {
    'title': AppText.yield,
    'subTitle': 'Name of Investment',
    'dateTime': '10/04/2024 22:04',
    'value': '+ SAR 100,000',
    'subValue': '+ \$100,00',
    'onHold': false,
  },
  {
    'title': AppText.refund,
    'subTitle': '',
    'dateTime': '10/04/2024 22:04',
    'value': '- SAR 100,000',
    'subValue': '',
    'onHold': true,
  },
];
