import 'package:SEFER/constant/info.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/constant/box_name.dart';
import 'package:SEFER/constant/style.dart';
import 'package:SEFER/views/home/my_wallet/passenger_wallet.dart';

import '../../../constant/colors.dart';
import '../../../controller/home/map_passenger_controller.dart';
import '../../../controller/payment/payment_controller.dart';
import '../../../main.dart';
import '../../widgets/elevated_btn.dart';

class CashConfirmPageShown extends StatelessWidget {
  CashConfirmPageShown({
    super.key,
  });
  PaymentController paymentController = Get.put(PaymentController());
  @override
  Widget build(BuildContext context) {
    return GetBuilder<MapPassengerController>(
        builder: (controller) => Positioned(
              right: 5,
              bottom: 5,
              left: 5,
              child: AnimatedContainer(
                duration: const Duration(milliseconds: 400),
                height: controller.isCashConfirmPageShown
                    ? controller.cashConfirmPageShown
                    : 0,
                decoration: BoxDecoration(
                    color: AppColor.secondaryColor,
                    borderRadius: BorderRadius.circular(15)),
                child: Padding(
                  padding: const EdgeInsets.symmetric(horizontal: 20),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
                            'Payment Method'.tr,
                            style: AppStyle.title.copyWith(fontSize: 22),
                          ),
                          // IconButton(
                          //   onPressed: () =>
                          //       controller.changeCashConfirmPageShown(),
                          //   icon: const Icon(Icons.close),
                          // ),
                        ],
                      ),
                      GetBuilder<PaymentController>(
                        builder: (paymentController) => Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            const Icon(
                              Icons.wallet_outlined,
                              size: 25,
                              color: AppColor.redColor,
                            ),
                            const SizedBox(
                              width: 20,
                            ),
                            Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  '${AppInformation.appName} Wallet'.tr,
                                  style: AppStyle.title,
                                ),
                                Text(
                                  // '${'Your Wallet balance is '.tr}JD ',
                                  '${'Your Wallet balance is '.tr} ${box.read(BoxName.passengerWalletTotal).toString()}${' \$'.tr}',
                                  style: AppStyle.subtitle,
                                ),
                              ],
                            ),
                            const Spacer(),
                            Checkbox.adaptive(
                              value: paymentController.isWalletChecked,
                              onChanged: (value) {
                                paymentController
                                    .onChangedPaymentMethodWallet(value);
                              },
                            )
                          ],
                        ),
                      ),
                      const Divider(
                        color: AppColor.accentColor,
                        thickness: 1,
                        height: 2,
                        indent: 1,
                      ),
                      Row(
                        children: [
                          Icon(
                            Icons.monetization_on,
                            color: Colors.green[400],
                          ),
                          const SizedBox(
                            width: 20,
                          ),
                          InkWell(
                            onTap: () {
                              controller.changeCashConfirmPageShown();
                              controller.isSearchingWindow = true;
                              controller.confirmRideForFirstDriver();
                              controller.update();
                            },
                            child: Text(
                              'CASH',
                              style: AppStyle.title,
                            ),
                          ),
                          const Spacer(),
                          GetBuilder<PaymentController>(
                              builder: (controller) => Checkbox.adaptive(
                                    value: controller.isCashChecked,
                                    onChanged: (value) {
                                      controller
                                          .onChangedPaymentMethodCash(value);
                                    },
                                  ))
                        ],
                      ),
                      const Divider(
                        color: AppColor.accentColor,
                        thickness: 1,
                        height: 2,
                        indent: 1,
                      ),
                      // GetBuilder<PaymentController>(
                      //     builder: (paymentController) =>
                      //         (paymentController.isWalletChecked == false &&
                      //                 paymentController.isCashChecked == true
                      //             ? MyElevatedButton(
                      //                 title: 'Next'.tr,
                      //                 onPressed: () {
                      //                   controller.changeCashConfirmPageShown();
                      //                 },
                      //               )
                      //             : const SizedBox())),
                      GetBuilder<PaymentController>(
                        builder: (paymentController) => (box
                                        .read(BoxName.passengerWalletTotal) ==
                                    null ||
                                double.parse(box
                                        .read(BoxName.passengerWalletTotal)) <
                                    controller.totalPassenger)
                            ? Column(
                                children: [
                                  MyElevatedButton(
                                    title: 'To use Wallet charge it'.tr,
                                    onPressed: () {
                                      Get.to(() => const PassengerWallet());
                                    },
                                    kolor: AppColor.redColor,
                                  ),
                                  MyElevatedButton(
                                    kolor: AppColor.greenColor,
                                    title: 'Next as Cash \$\$!'.tr,
                                    onPressed: () {
                                      paymentController.isCashChecked = true;
                                      paymentController.isWalletChecked = false;
                                      paymentController.update();
                                      controller.changeCashConfirmPageShown();
                                      controller.isSearchingWindow = true;
                                      controller.confirmRideForFirstDriver();
                                      controller.update();
                                    },
                                  ),
                                ],
                              )
                            : MyElevatedButton(
                                title: 'Next'.tr,
                                onPressed: () {
                                  controller.changeCashConfirmPageShown();
                                  controller.isSearchingWindow = true;
                                  controller.confirmRideForFirstDriver();
                                  controller.update();
                                },
                              ), // Add a fallback widget if none of the conditions are met
                      )
                    ],
                  ),
                ),
              ),
            ));
  }
}
