import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:gap/gap.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:tanami_app/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 '../../../../../../core/utils/language/localizations_delegate.dart';
import '../../../../../../shared/components/button_widget.dart';
import '../../../../../countrySelection/bloc/choose_country_bloc.dart';
import '../../../../../countrySelection/bloc/choose_country_state.dart';
import '../../bloc/payment/invest_payment_bloc.dart';
import '../../bloc/payment/invest_payment_state.dart';

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

  @override
  Widget build(BuildContext context) {
    var localizations = AppLocalizations.of(context);
    return Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        BlocBuilder<InvestPaymentBloc, InvestPaymentState>(
          builder: (context, state) {
            return BlocBuilder<RadioBloc, RadioState>(
              builder: (context, radioState) {
                int selectedIndex = 0;
                if (radioState is RadioSelectionChanged) {
                  selectedIndex = radioState.selectedIndex;
                }
                return selectedIndex == 1
                    ? InkWell(
                        onTap: () {
                          goRouter.pushNamed(RouteName.walletDetails,
                              pathParameters: {
                                "type": 'confirm-investment',
                              });
                        },
                        child: Container(
                          margin: const EdgeInsets.all(10.0),
                          height: 65.h,
                          width: double.infinity,
                          decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(22.r),
                              color: state.isFormValid
                                  ? AppColor.plainBlack
                                  : AppColor.inactiveBtnColor),
                          child: Center(
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.center,
                              children: [
                                SvgPicture.asset(
                                  AppImages.applePayIcon,
                                  color: AppColor.plainWhite,
                                  height: 32,
                                  width: 32,
                                ),
                                const Gap(5),
                                Text(
                                  localizations
                                      .translate(AppText.payWithAppleText),
                                  style: GoogleFonts.dmSans(
                                    color: state.isFormValid
                                        ? AppColor.plainWhite
                                        : AppColor.inactiveBtnTxtColor,
                                    fontSize: 14.sp,
                                    fontWeight: FontWeight.w700,
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      )
                    : Container(
                        margin: const EdgeInsets.symmetric(
                          horizontal: 16,
                        ),
                        width: 1.sw,
                        height: 56.h,
                        child: ButtonWidget().elevatedBtn(
                            txtClr: state.isFormValid
                                ? AppColor.plainWhite
                                : AppColor.inactiveBtnTxtColor,
                            function: () {
                              if (state.isFormValid) {
                                goRouter.pushNamed(RouteName.otpScreen,
                                    pathParameters: {
                                      "fromScreen": "confirm-investment"
                                    });
                              }
                            },
                            text: localizations
                                .translate(AppText.confirmInvestmentText),
                            clr: state.isFormValid
                                ? AppColor.primaryColor2
                                : AppColor.inactiveBtnColor),
                      );
              },
            );
          },
        ),
        // const Gap(5),
        // ButtonWidget().textBorderBtn(
        //   borderClr: AppColor.txtBorderColor,
        //   clr: AppColor.plainWhite,
        //   function: () {
        //     goRouter.pop();
        //   },
        //   text: AppText.backText,
        // ),
      ],
    );
  }
}
