import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:ride/controller/payment/payment_controller.dart';
import 'package:ride/views/widgets/elevated_btn.dart';

import '../../../constant/colors.dart';
import '../../../constant/style.dart';
import '../../../controller/home/map_passenger_controller.dart';

GetBuilder<MapPassengerController> buttomSheetMapPage() {
  Get.put(PaymentController());
  return GetBuilder<MapPassengerController>(
      builder: (controller) => controller.isBottomSheetShown &&
              controller.rideConfirm == false
          ? Positioned(
              left: 5,
              bottom: 0,
              right: 5,
              child: AnimatedContainer(
                // clipBehavior: Clip.antiAliasWithSaveLayer,
                curve: Curves.easeInCirc,
                onEnd: () {
                  controller.height = 250;
                },
                height: controller.heightBottomSheetShown,
                duration: const Duration(seconds: 2),
                child: Column(
                  children: [
                    controller.data.isEmpty
                        ? const SizedBox()
                        : Container(
                            // width: Get.width * .9,
                            height: 100,
                            decoration: BoxDecoration(
                                color: AppColor.secondaryColor,
                                boxShadow: [
                                  const BoxShadow(
                                      color: AppColor.accentColor,
                                      offset: Offset(2, 2)),
                                  BoxShadow(
                                      color:
                                          AppColor.accentColor.withOpacity(.4),
                                      offset: const Offset(-2, -2))
                                ],
                                borderRadius: const BorderRadius.all(
                                    Radius.circular(15))),
                            child: Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                Padding(
                                  padding: const EdgeInsets.all(8.0),
                                  child: Image.asset(
                                    'assets/images/jeep.png',
                                    width: 50,
                                    fit: BoxFit.fill,
                                    repeat: ImageRepeat.repeatX,
                                  ),
                                ),
                                Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Text(
                                        '${'Your Ride Duration is '.tr}${controller.duration} minutes'),
                                    Text(
                                        '${'You will be thier in'.tr} ${DateFormat('h:mm a').format(controller.newTime)}'),
                                    Text(
                                        '${'You trip distance is'.tr}  ${controller.distance} KM')
                                  ],
                                ),
                                Padding(
                                  padding:
                                      const EdgeInsets.only(right: 5, left: 5),
                                  child: Column(
                                    crossAxisAlignment:
                                        CrossAxisAlignment.center,
                                    children: [
                                      Text(
                                        '${'Fee is'.tr} \n${controller.totalPassenger.toStringAsFixed(2)}',
                                        style: AppStyle.subtitle,
                                      ),
                                      controller.promoTaken
                                          ? const Icon(
                                              Icons.filter_vintage_rounded,
                                              color: AppColor.redColor,
                                            )
                                          : const SizedBox(
                                              height: 0,
                                            )
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          ),
                    const SizedBox(
                      height: 5,
                    ),
                    Container(
                      // height: 130,
                      decoration: BoxDecoration(
                          color: AppColor.secondaryColor,
                          boxShadow: [
                            const BoxShadow(
                                color: AppColor.accentColor,
                                offset: Offset(2, 2)),
                            BoxShadow(
                                color: AppColor.accentColor.withOpacity(.4),
                                offset: const Offset(-2, -2))
                          ],
                          borderRadius:
                              const BorderRadius.all(Radius.circular(15))),
                      child: controller.data.isEmpty
                          ? const SizedBox()
                          : Center(
                              child: Padding(
                                padding:
                                    const EdgeInsets.symmetric(horizontal: 5),
                                child: Column(
                                  children: [
                                    Row(
                                      children: [
                                        const Icon(
                                          Icons.location_on,
                                          color: AppColor.redColor,
                                        ),
                                        const SizedBox(
                                          width: 10,
                                        ),
                                        Text(
                                          'From : '.tr,
                                          style: AppStyle.subtitle,
                                        ),
                                        Text(
                                          controller.data[0]['start_address']
                                              .toString(),
                                          style: AppStyle.subtitle,
                                        )
                                      ],
                                    ),
                                    Row(
                                      children: [
                                        const Icon(
                                            Icons.location_searching_rounded),
                                        const SizedBox(
                                          width: 10,
                                        ),
                                        Text(
                                          'To : '.tr,
                                          style: AppStyle.subtitle,
                                        ),
                                        Text(
                                          controller.data[0]['end_address'],
                                          style: AppStyle.subtitle,
                                        ),
                                      ],
                                    ),
                                    const Divider(
                                      color: AppColor.accentColor,
                                      thickness: 1,
                                      height: 2,
                                      indent: 1,
                                    ),
                                    SizedBox(
                                      height: 40,
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.center,
                                        children: [
                                          Container(
                                            decoration: BoxDecoration(
                                              color: AppColor.secondaryColor,
                                              borderRadius:
                                                  BorderRadius.circular(12),
                                              // border: Border.all(),
                                            ),
                                            child: Row(
                                              children: [
                                                Icon(
                                                  Icons.monetization_on,
                                                  color: Colors.green[400],
                                                ),
                                                InkWell(
                                                  onTap: () async {
                                                    controller
                                                        .changeCashConfirmPageShown();
                                                    PaymentController()
                                                        .getPassengerWallet();
                                                  },
                                                  child: GetBuilder<
                                                      PaymentController>(
                                                    builder:
                                                        (paymentController) =>
                                                            paymentController
                                                                    .isCashChecked
                                                                ? Text(
                                                                    'CASH',
                                                                    style: AppStyle
                                                                        .title,
                                                                  )
                                                                : Text(
                                                                    'Sefer Wallet',
                                                                    style: AppStyle
                                                                        .title,
                                                                  ),
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                          const SizedBox(
                                            width: 40,
                                          ),
                                          GetBuilder<PaymentController>(
                                              builder:
                                                  (paymentController) =>
                                                      Container(
                                                        decoration:
                                                            BoxDecoration(
                                                          color: AppColor
                                                              .secondaryColor,
                                                          borderRadius:
                                                              BorderRadius
                                                                  .circular(12),
                                                        ),
                                                        child: Row(
                                                          children: [
                                                            Icon(
                                                              Icons
                                                                  .qr_code_2_rounded,
                                                              color: Colors
                                                                  .green[400],
                                                            ),
                                                            InkWell(
                                                              onTap: () {
                                                                if (controller
                                                                        .promoTaken ==
                                                                    false) {
                                                                  Get.defaultDialog(
                                                                      title: 'Add Promo'.tr,
                                                                      content: Column(
                                                                        children: [
                                                                          SizedBox(
                                                                            width:
                                                                                Get.width * .7,
                                                                            child:
                                                                                TextFormField(
                                                                              controller: controller.promo,
                                                                              decoration: InputDecoration(
                                                                                labelText: 'Promo Code'.tr,
                                                                                hintText: 'Enter promo code'.tr,
                                                                                border: OutlineInputBorder(
                                                                                  borderRadius: BorderRadius.circular(10),
                                                                                ),
                                                                                filled: true,
                                                                                fillColor: Colors.grey[200],
                                                                                focusedBorder: OutlineInputBorder(
                                                                                  borderSide: const BorderSide(
                                                                                    color: AppColor.primaryColor,
                                                                                    width: 2.0,
                                                                                  ),
                                                                                  borderRadius: BorderRadius.circular(10),
                                                                                ),
                                                                                errorBorder: OutlineInputBorder(
                                                                                  borderSide: const BorderSide(
                                                                                    color: Colors.red,
                                                                                    width: 2.0,
                                                                                  ),
                                                                                  borderRadius: BorderRadius.circular(10),
                                                                                ),
                                                                                enabledBorder: OutlineInputBorder(
                                                                                  borderSide: const BorderSide(
                                                                                    color: Colors.grey,
                                                                                    width: 1.0,
                                                                                  ),
                                                                                  borderRadius: BorderRadius.circular(10),
                                                                                ),
                                                                              ),
                                                                            ),
                                                                          ),
                                                                          MyElevatedButton(
                                                                            title:
                                                                                'Add Promo'.tr,
                                                                            onPressed:
                                                                                () async {
                                                                              controller.applyPromoCodeToPassenger();
                                                                            },
                                                                          )
                                                                        ],
                                                                      ));
                                                                } else {
                                                                  Get.snackbar(
                                                                      'You have promo!'
                                                                          .tr,
                                                                      '',
                                                                      backgroundColor:
                                                                          AppColor
                                                                              .redColor);
                                                                }
                                                              },
                                                              child: Text(
                                                                'Add Promo'.tr,
                                                                style: AppStyle
                                                                    .title,
                                                              ),
                                                            ),
                                                          ],
                                                        ),
                                                      )),
                                        ],
                                      ),
                                    ),
                                    Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        TextButton(
                                          onPressed: () {
                                            Get.defaultDialog(
                                              title: 'How Many Passengers?'.tr,
                                              titleStyle: AppStyle.title,
                                              content: Column(
                                                children: [
                                                  Text(
                                                    'Allowed up to 4 Passengers.'
                                                        .tr,
                                                    style: AppStyle.title,
                                                  ),
                                                  SizedBox(
                                                    height:
                                                        200, // Set the desired height here
                                                    child: CupertinoPicker(
                                                      itemExtent: 32,
                                                      onSelectedItemChanged:
                                                          (index) {
                                                        controller
                                                            .onChangedPassengerCount(
                                                                index + 1);
                                                      },
                                                      children: [
                                                        Text('1 Passenger'.tr),
                                                        Text('2 Passengers'.tr),
                                                        Text('3 Passengers'.tr),
                                                        Text('4 Passengers'.tr),
                                                      ],
                                                    ),
                                                  ),
                                                  MyElevatedButton(
                                                    title: 'Back',
                                                    onPressed: () => Get.back(),
                                                  )
                                                ],
                                              ),
                                            );
                                          },
                                          child: Row(
                                            mainAxisAlignment:
                                                MainAxisAlignment.spaceBetween,
                                            children: [
                                              Text('How Many Passengers?'.tr,
                                                  style: AppStyle.title),
                                              const SizedBox(
                                                width: 10,
                                              ),
                                              Container(
                                                decoration: BoxDecoration(
                                                    border: Border.all()),
                                                child: Padding(
                                                  padding:
                                                      const EdgeInsets.all(3.0),
                                                  child: Text(
                                                      controller
                                                          .selectedPassengerCount
                                                          .toString(),
                                                      style: AppStyle.title),
                                                ),
                                              ),
                                            ],
                                          ),
                                        ),
                                        MyElevatedButton(
                                          title: 'Confirm Selection'.tr,
                                          onPressed: () {
                                            controller.changeConfirmRide();

                                            // Get.to(() => UsePaypal(
                                            //       sandboxMode: true,
                                            // clientId:
                                            //     "AXE7bR3WzFEfAInUA2PBDOsW4zolx11Qr3jVOOjjJ7KGDLY3tnMIhZgyFT5Qkvj1NKWPaE8VZbG4UrZs",
                                            // secretKey:
                                            //     "EJPW01FKqOm-SKKP16LQ_2cr3b124aZgmE0vi3JfbkWgLffv2xIjT4iCIfQv8RYn3W8h4DzxgZu_UxZC",
                                            // returnURL:
                                            //     "https://samplesite.com/return",
                                            // cancelURL:
                                            //     "https://samplesite.com/cancel",
                                            // transactions: const [
                                            //   {
                                            //     "amount": {
                                            //       "total": '10.12',
                                            //       "currency": "USD",
                                            //       "details": {
                                            //         "subtotal": '10.12',
                                            //         "shipping": '0',
                                            //         "shipping_discount": 0
                                            //       }
                                            //     },
                                            //     "description":
                                            //         "The payment transaction description.",
                                            //     "payment_options": {
                                            //       "allowed_payment_method":
                                            //           "INSTANT_FUNDING_SOURCE"
                                            //     },
                                            //     "item_list": {
                                            //       "items": [
                                            //         {
                                            //           "name":
                                            //               "A demo product",
                                            //           "quantity": 1,
                                            //           "price": '10.12',
                                            //           "currency": "USD"
                                            //         }
                                            //       ],
                                            //       // shipping address is not required though
                                            //       "shipping_address": {
                                            //         "recipient_name":
                                            //             "Jane Foster",
                                            //         "line1": "Travis County",
                                            //         "line2": "",
                                            //         "city": "Austin",
                                            //         "country_code": "US",
                                            //         "postal_code": "73301",
                                            //         "phone": "+00000000",
                                            //         "state": "Texas"
                                            //       },
                                            //     }
                                            //   }
                                            // ],
                                            // note:
                                            //     "Contact us for any questions on your order.",
                                            // onSuccess: (Map params) async {
                                            //   print("onSuccess: $params");
                                            // },
                                            // onError: (error) {
                                            //   print("onError: $error");
                                            // },
                                            // onCancel: (params) {
                                            //   print('cancelled: $params');
                                            // },
                                            // )
                                            // );
                                          },
                                        ),
                                      ],
                                    )
                                  ],
                                ),
                              ),
                            ),
                    ),
                  ],
                ),
              ),
            )
          : const SizedBox());
}

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

  @override
  Widget build(BuildContext context) {
    return GetBuilder<MapPassengerController>(
        builder: (controller) => Column(
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Text(
                      '${'distance is'.tr} ${controller.data[0]['distance']['text']}',
                      style: AppStyle.title,
                    ),
                    Text(
                      '${'duration is'.tr} ${controller.data[0]['duration']['text']}',
                      style: AppStyle.title,
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Text(
                      'Cost for .21/km ${controller.cost.toStringAsFixed(2)} ',
                      style: AppStyle.title,
                    ),
                    Text(
                      'costDuration ${controller.averageDuration.toStringAsFixed(2)} is ${controller.costDuration.toStringAsFixed(2)} ',
                      style: AppStyle.title,
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    Text(
                      'totalDriver  ${controller.totalDriver.toStringAsFixed(2)}',
                      style: AppStyle.title,
                    ),
                    Text(
                      'totaME  ${controller.totalME.toStringAsFixed(2)} ',
                      style: AppStyle.title,
                    ),
                  ],
                ),
                Text(
                  'Cost for passenger ${controller.totalPassenger.toStringAsFixed(2)} ',
                  style: AppStyle.title,
                ),
              ],
            ));
  }
}
