import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:SEFER/constant/colors.dart';
import 'package:SEFER/constant/style.dart';
import 'package:SEFER/controller/home/payment/captain_wallet_controller.dart';
import 'package:SEFER/controller/payment/payment_controller.dart';

import '../../../constant/box_name.dart';
import '../../../main.dart';
import '../../widgets/elevated_btn.dart';

class PointsCaptain extends StatelessWidget {
  PaymentController paymentController = Get.put(PaymentController());
  CaptainWalletController captainWalletController =
      Get.put(CaptainWalletController());

  PointsCaptain({
    super.key,
    required this.kolor,
    required this.countPoint,
    required this.pricePoint,
  });
  final Color kolor;
  final String countPoint;
  double pricePoint;

  @override
  Widget build(BuildContext context) {
    return InkWell(
      onTap: () async {
        box.read(BoxName.countryCode) == 'Egypt'
            ? Get.defaultDialog(
                title: 'Which method you will pay'.tr,
                titleStyle: AppStyle.title,
                content: Column(
                  children: [
                    MyElevatedButton(
                      title: '💳 Pay with Credit Card'.tr,
                      onPressed: () async {
                        Get.back();
                        await paymentController.payWithPayMob(
                            context,
                            pricePoint.toStringAsFixed(2),
                            box.read(BoxName.countryCode) == 'Egypt'
                                ? 'EGP'
                                : 'JOD', () async {
                          await captainWalletController.addDriverPayment(
                              'visa', pricePoint);
                          await captainWalletController.addDriverWallet(
                              'visa', countPoint);
                          await captainWalletController
                              .getCaptainWalletFromBuyPoints();
                        });
                      }, //51524
                    ),
                    // Add some spacing between buttons
                    MyElevatedButton(
                      kolor: AppColor.yellowColor,
                      title: '💰 Pay with Wallet'.tr,
                      onPressed: () async {
                        Get.back();
                        await paymentController.payWithPayMobWallet(
                            context,
                            pricePoint.toStringAsFixed(2),
                            box.read(BoxName.countryCode) == 'Egypt'
                                ? 'EGP'
                                : 'JOD', () async {
                          await captainWalletController.addDriverPayment(
                              'visa', pricePoint);
                          await captainWalletController.addDriverWallet(
                              'visa', countPoint);
                          await captainWalletController
                              .getCaptainWalletFromBuyPoints();
                        });
                      },
                    ),
                  ],
                ))
            : await paymentController.makePaymentStripe(pricePoint,
                box.read(BoxName.countryCode) == 'Jordan' ? 'jod' : 'egp',
                () async {
                await captainWalletController.addDriverPayment(
                    'visa', pricePoint);
                await captainWalletController.addDriverWallet(
                    'visa', countPoint);
                await captainWalletController.getCaptainWalletFromBuyPoints();
              });
      },
      child: Container(
          width: Get.width * .22,
          height: Get.width * .15,
          margin: const EdgeInsets.all(4),
          decoration: BoxDecoration(
            color: kolor,
            border: Border.all(color: AppColor.accentColor),
            borderRadius: BorderRadius.circular(12),
            shape: BoxShape.rectangle,
          ),
          child: Center(
            child: Column(
              children: [
                Text(
                  '$countPoint ${'Point'.tr}',
                  style: AppStyle.subtitle,
                ),
                Text(
                  '$pricePoint ${box.read(BoxName.countryCode) == 'Jordan' ? 'JOD'.tr : 'LE'.tr}',
                  style: AppStyle.title,
                ),
              ],
            ),
          )),
    );
  }
}
