// ignore_for_file: depend_on_referenced_packages, use_build_context_synchronously

import 'package:cached_network_image/cached_network_image.dart';
import 'package:driver/app/models/parcel_model.dart';
import 'package:driver/app/models/user_model.dart';
import 'package:driver/app/modules/parcel_detail_details/views/parcel_booking_details_view.dart';
import 'package:driver/app/modules/reason_for_cancel_parcel/views/reason_for_cancel_parcel_view.dart';
import 'package:driver/app/modules/search_intercity_ride/search_intercity_view/search_ride_view.dart';
import 'package:driver/app/routes/app_pages.dart';
import 'package:driver/constant/booking_status.dart';
import 'package:driver/constant/constant.dart';
import 'package:driver/constant/send_notification.dart';
import 'package:driver/constant_widgets/custom_dialog_box.dart';
import 'package:driver/constant_widgets/custom_loader.dart';
import 'package:driver/constant_widgets/pick_drop_point_view.dart';
import 'package:driver/constant_widgets/round_shape_button.dart';
import 'package:driver/constant_widgets/show_toast_dialog.dart';
import 'package:driver/extension/date_time_extension.dart';
import 'package:driver/theme/app_them_data.dart';
import 'package:driver/theme/responsive.dart';
import 'package:driver/utils/dark_theme_provider.dart';
import 'package:driver/utils/fire_store_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:provider/provider.dart';

import '../controllers/parcel_ride_for_home_controller.dart';

class ParcelRideForHomeView extends GetView<ParcelRideForHomeController> {
  const ParcelRideForHomeView({super.key});

  @override
  Widget build(BuildContext context) {
    final themeChange = Provider.of<DarkThemeProvider>(context);
    return GetX(
      init: ParcelRideForHomeController(),
      builder: (controller) {
        return Scaffold(
            backgroundColor: themeChange.isDarkTheme() ? AppThemData.black : AppThemData.grey25,
            body: Column(
              children: [
                if (controller.parcelRideList.isNotEmpty)
                  Padding(
                    padding: EdgeInsets.fromLTRB(16, 0, 16, 16),
                    child: GestureDetector(
                      onTap: () {
                        Get.to(() => SearchRideView(selectedRideType: 'parcel'));
                      },
                      child: Container(
                        width: Responsive.width(100, context),
                        height: 56,
                        padding: const EdgeInsets.all(16),
                        decoration: ShapeDecoration(
                          color: themeChange.isDarkTheme() ? AppThemData.black : AppThemData.white,
                          shape: RoundedRectangleBorder(
                            side: BorderSide(width: 1, color: themeChange.isDarkTheme() ? AppThemData.grey900 : AppThemData.grey50),
                            borderRadius: BorderRadius.circular(100),
                          ),
                        ),
                        child: Row(
                          mainAxisSize: MainAxisSize.min,
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            Icon(
                              Icons.search_rounded,
                              color: themeChange.isDarkTheme() ? AppThemData.grey400 : AppThemData.grey500,
                            ),
                            const SizedBox(width: 8),
                            Expanded(
                              child: Text(
                                "Search Ride".tr,
                                style: GoogleFonts.inter(
                                  color: themeChange.isDarkTheme() ? AppThemData.grey400 : AppThemData.grey500,
                                  fontSize: 16,
                                  fontWeight: FontWeight.w400,
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
                Expanded(
                  child: SingleChildScrollView(
                    child: controller.parcelRideList.isEmpty
                        ? Column(
                            children: [
                              SvgPicture.asset("assets/icon/ic_no_rides.svg"),
                              const SizedBox(
                                height: 24,
                              ),
                              Text(
                                "No Rides Found".tr,
                                textAlign: TextAlign.center,
                                style: GoogleFonts.inter(
                                  color: themeChange.isDarkTheme() ? AppThemData.grey25 : AppThemData.grey950,
                                  fontSize: 18,
                                  fontWeight: FontWeight.w700,
                                ),
                              ),
                              Padding(
                                padding: const EdgeInsets.only(left: 20, right: 20, top: 4, bottom: 24),
                                child: Text(
                                  "Your ride history is currently empty. Start your journey with MyTaxi by riding your first ride now!".tr,
                                  textAlign: TextAlign.center,
                                  style: GoogleFonts.inter(
                                    color: themeChange.isDarkTheme() ? AppThemData.grey25 : AppThemData.grey950,
                                    fontSize: 14,
                                    fontWeight: FontWeight.w400,
                                  ),
                                ),
                              ),
                              RoundShapeButton(
                                  title: "Search Ride".tr,
                                  buttonColor: AppThemData.primary500,
                                  buttonTextColor: AppThemData.black,
                                  onTap: () {
                                    Get.to(() => SearchRideView(selectedRideType: 'parcel'));
                                  },
                                  size: Size(200, 52))
                            ],
                          ).paddingOnly(top: 100)
                        : ListView.builder(
                            shrinkWrap: true,
                            itemCount: controller.parcelRideList.length,
                            itemBuilder: (context, index) {
                              RxBool isOpen = false.obs;
                              ParcelModel parcelModel = controller.parcelRideList[index];
                              return GestureDetector(
                                onTap: () {
                                  isOpen.value = !isOpen.value;
                                },
                                child: Container(
                                  width: Responsive.width(100, context),
                                  padding: const EdgeInsets.only(left: 16, right: 16, top: 16),
                                  margin: const EdgeInsets.only(top: 12, left: 16, right: 16),
                                  decoration: ShapeDecoration(
                                    shape: RoundedRectangleBorder(
                                      side: BorderSide(width: 1, color: themeChange.isDarkTheme() ? AppThemData.grey800 : AppThemData.grey100),
                                      borderRadius: BorderRadius.circular(12),
                                    ),
                                  ),
                                  child: Column(
                                    mainAxisSize: MainAxisSize.min,
                                    mainAxisAlignment: MainAxisAlignment.start,
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      Row(
                                        mainAxisSize: MainAxisSize.min,
                                        mainAxisAlignment: MainAxisAlignment.start,
                                        crossAxisAlignment: CrossAxisAlignment.center,
                                        children: [
                                          Text(
                                            parcelModel.bookingTime == null ? "" : parcelModel.bookingTime!.toDate().dateMonthYear(),
                                            style: GoogleFonts.inter(
                                              color: themeChange.isDarkTheme() ? AppThemData.grey400 : AppThemData.grey500,
                                              fontSize: 14,
                                              fontWeight: FontWeight.w400,
                                            ),
                                          ),
                                          const SizedBox(width: 8),
                                          Container(
                                            height: 15,
                                            decoration: ShapeDecoration(
                                              shape: RoundedRectangleBorder(
                                                side: BorderSide(
                                                  width: 1,
                                                  strokeAlign: BorderSide.strokeAlignCenter,
                                                  color: themeChange.isDarkTheme() ? AppThemData.grey800 : AppThemData.grey100,
                                                ),
                                              ),
                                            ),
                                          ),
                                          const SizedBox(width: 8),
                                          Expanded(
                                            child: Text(
                                              parcelModel.bookingTime == null ? "" : parcelModel.bookingTime!.toDate().time(),
                                              style: GoogleFonts.inter(
                                                color: themeChange.isDarkTheme() ? AppThemData.grey400 : AppThemData.grey500,
                                                fontSize: 14,
                                                fontWeight: FontWeight.w400,
                                              ),
                                            ),
                                          ),
                                          const SizedBox(width: 8),
                                          GestureDetector(
                                            onTap: () {
                                              Get.to(
                                                ParcelBookingDetailsView(),
                                                arguments: {"bookingId": parcelModel.id ?? ''},
                                              );
                                            },
                                            child: Icon(
                                              Icons.keyboard_arrow_right_sharp,
                                              color: themeChange.isDarkTheme() ? AppThemData.grey400 : AppThemData.grey500,
                                            ),
                                          )
                                        ],
                                      ),
                                      const SizedBox(height: 12),
                                      Container(
                                        padding: const EdgeInsets.only(bottom: 12),
                                        child: Row(
                                          mainAxisSize: MainAxisSize.min,
                                          mainAxisAlignment: MainAxisAlignment.start,
                                          crossAxisAlignment: CrossAxisAlignment.center,
                                          children: [
                                            FutureBuilder<UserModel?>(
                                              future: FireStoreUtils.getUserProfile(parcelModel.customerId ?? ''),
                                              builder: (context, snapshot) {
                                                if (snapshot.connectionState == ConnectionState.waiting) {
                                                  return Center(
                                                    child: CustomLoader(),
                                                  );
                                                }
                                                if (!snapshot.hasData || snapshot.data == null) {
                                                  return Container();
                                                }
                                                UserModel customerModel = snapshot.data ?? UserModel();
                                                return Container(
                                                  width: 60,
                                                  height: 60,
                                                  margin: const EdgeInsets.only(right: 10),
                                                  clipBehavior: Clip.antiAlias,
                                                  decoration: ShapeDecoration(
                                                    color: themeChange.isDarkTheme() ? AppThemData.grey950 : AppThemData.white,
                                                    shape: RoundedRectangleBorder(
                                                      borderRadius: BorderRadius.circular(200),
                                                    ),
                                                  ),
                                                  child: CachedNetworkImage(
                                                    imageUrl: (customerModel.profilePic != null && customerModel.profilePic!.isNotEmpty)
                                                        ? customerModel.profilePic!
                                                        : Constant.profileConstant,
                                                    fit: BoxFit.cover,
                                                    placeholder: (context, url) => Center(
                                                      child: CustomLoader(),
                                                    ),
                                                    errorWidget: (context, url, error) => Image.asset(Constant.userPlaceHolder),
                                                  ),
                                                );
                                              },
                                            ),
                                            const SizedBox(width: 12),
                                            Expanded(
                                              child: Column(
                                                mainAxisSize: MainAxisSize.min,
                                                mainAxisAlignment: MainAxisAlignment.center,
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                children: [
                                                  Text(
                                                    "Id".trParams({"id": parcelModel.id!.substring(0, 5)}),
                                                    //'ID: ${parcelModel.id!.substring(0, 5)}',
                                                    style: GoogleFonts.inter(
                                                      color: themeChange.isDarkTheme() ? AppThemData.grey25 : AppThemData.grey950,
                                                      fontSize: 16,
                                                      fontWeight: FontWeight.w600,
                                                    ),
                                                  ),
                                                  const SizedBox(height: 2),
                                                  Text(
                                                    "Ride_Date".trParams({"ridedate": Constant.formatDate(Constant.parseDate(parcelModel.startDate))}),
                                                    // 'Ride Start Date: ${Constant.formatDate(Constant.parseDate(parcelModel.startDate))}',
                                                    style: GoogleFonts.inter(
                                                      color: themeChange.isDarkTheme() ? AppThemData.grey25 : AppThemData.grey950,
                                                      fontSize: 14,
                                                      fontWeight: FontWeight.w400,
                                                    ),
                                                  ),
                                                  // Text(
                                                  //   (bookingModel.paymentStatus ?? false) ? 'Payment is Completed'.tr : 'Payment is Pending'.tr,
                                                  //   style: GoogleFonts.inter(
                                                  //     color: themeChange.isDarkTheme() ? AppThemData.grey25 : AppThemData.grey950,
                                                  //     fontSize: 14,
                                                  //     fontWeight: FontWeight.w400,
                                                  //   ),
                                                  // ),
                                                ],
                                              ),
                                            ),
                                            const SizedBox(width: 16),
                                            Column(
                                              mainAxisSize: MainAxisSize.min,
                                              mainAxisAlignment: MainAxisAlignment.end,
                                              crossAxisAlignment: CrossAxisAlignment.end,
                                              children: [
                                                Text(
                                                  Constant.amountToShow(amount: Constant.calculateParcelFinalAmount(parcelModel).toString()),
                                                  // amount: Constant.calculateInterCityFinalAmount(bookingModel).toStringAsFixed(2)),
                                                  textAlign: TextAlign.right,
                                                  style: GoogleFonts.inter(
                                                    color: themeChange.isDarkTheme() ? AppThemData.grey25 : AppThemData.grey950,
                                                    fontSize: 16,
                                                    fontWeight: FontWeight.w500,
                                                  ),
                                                ),
                                                const SizedBox(height: 2),
                                                Row(
                                                  mainAxisSize: MainAxisSize.min,
                                                  mainAxisAlignment: MainAxisAlignment.start,
                                                  crossAxisAlignment: CrossAxisAlignment.center,
                                                  children: [
                                                    SvgPicture.asset("assets/icon/ic_weight.svg"),
                                                    const SizedBox(width: 6),
                                                    Text(
                                                      '${parcelModel.weight}',
                                                      style: GoogleFonts.inter(
                                                        color: AppThemData.primary500,
                                                        fontSize: 16,
                                                        fontWeight: FontWeight.w400,
                                                      ),
                                                    ),
                                                  ],
                                                ),
                                              ],
                                            ),
                                          ],
                                        ),
                                      ),
                                      Obx(
                                        () => Visibility(
                                          visible: isOpen.value,
                                          child: Column(
                                            children: [
                                              const SizedBox(height: 12),
                                              PickDropPointView(pickUpAddress: parcelModel.pickUpLocationAddress ?? '', dropAddress: parcelModel.dropLocationAddress ?? ''),
                                              const SizedBox(height: 16),
                                              Row(
                                                mainAxisAlignment: MainAxisAlignment.start,
                                                crossAxisAlignment: CrossAxisAlignment.start,
                                                children: [
                                                  Constant.isParcelBid == false
                                                      ? parcelModel.bookingStatus == BookingStatus.bookingPlaced
                                                          ? Row(
                                                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                              crossAxisAlignment: CrossAxisAlignment.center,
                                                              children: [
                                                                RoundShapeButton(
                                                                  title: "Cancel Ride".tr,
                                                                  buttonColor: AppThemData.danger500,
                                                                  buttonTextColor: AppThemData.white,
                                                                  onTap: () {
                                                                    showDialog(
                                                                        context: context,
                                                                        builder: (BuildContext context) {
                                                                          return CustomDialogBox(
                                                                              themeChange: themeChange,
                                                                              title: "Cancel Ride".tr,
                                                                              negativeButtonColor: themeChange.isDarkTheme() ? AppThemData.grey950 : AppThemData.grey50,
                                                                              negativeButtonTextColor: themeChange.isDarkTheme() ? AppThemData.grey50 : AppThemData.grey950,
                                                                              positiveButtonColor: AppThemData.danger500,
                                                                              positiveButtonTextColor: AppThemData.grey25,
                                                                              descriptions: "Are you sure you want cancel this parcel?".tr,
                                                                              positiveString: "Cancel parcel".tr,
                                                                              negativeString: "Cancel".tr,
                                                                              positiveClick: () async {
                                                                                Navigator.pop(context);
                                                                                List rejectedId = parcelModel.rejectedDriverId ?? [];
                                                                                rejectedId.add(FireStoreUtils.getCurrentUid());
                                                                                parcelModel.bookingStatus = BookingStatus.bookingRejected;
                                                                                parcelModel.rejectedDriverId = rejectedId;
                                                                                parcelModel.updateAt = Timestamp.now();
                                                                                FireStoreUtils.setParcelBooking(parcelModel).then((value) async {
                                                                                  if (value == true) {
                                                                                    ShowToastDialog.showToast("Parcel cancelled successfully!".tr);
                                                                                    // DriverUserModel? driverModel =
                                                                                    //     await FireStoreUtils.getDriverUserProfile(bookingModel!.driverId.toString());
                                                                                    UserModel? receiverUserModel =
                                                                                        await FireStoreUtils.getUserProfile(parcelModel.customerId.toString());
                                                                                    Map<String, dynamic> playLoad = <String, dynamic>{"bookingId": parcelModel.id};

                                                                                    await SendNotification.sendOneNotification(
                                                                                        type: "order",
                                                                                        token: receiverUserModel!.fcmToken.toString(),
                                                                                        title: 'Your Parcel is Rejected',
                                                                                        customerId: receiverUserModel.id,
                                                                                        senderId: FireStoreUtils.getCurrentUid(),
                                                                                        bookingId: parcelModel.id.toString(),
                                                                                        driverId: parcelModel.driverId.toString(),isBooking: false,
                                                                                        body:
                                                                                            'Your parcel #${parcelModel.id.toString().substring(0, 5)} has been Rejected by Driver.',
                                                                                        // body: 'Your ride has been rejected by ${driverModel!.fullName}.',
                                                                                        payload: playLoad);

                                                                                    Navigator.pop(context);
                                                                                  } else {
                                                                                    ShowToastDialog.showToast("Something went wrong!".tr);
                                                                                    Navigator.pop(context);
                                                                                  }
                                                                                });
                                                                              },
                                                                              negativeClick: () {
                                                                                Navigator.pop(context);
                                                                              },
                                                                              img: Image.asset(
                                                                                "assets/icon/ic_close.png",
                                                                                height: 58,
                                                                                width: 58,
                                                                              ));
                                                                        });
                                                                  },
                                                                  size: Size(Responsive.width(40, context), 42),
                                                                ),
                                                                SizedBox(
                                                                  width: 4,
                                                                ),
                                                                RoundShapeButton(
                                                                  title: "Accept".tr,
                                                                  buttonColor: AppThemData.primary500,
                                                                  buttonTextColor: AppThemData.black,
                                                                  onTap: () {
                                                                    if (double.parse(Constant.userModel!.walletAmount.toString()) >=
                                                                        double.parse(Constant.minimumAmountToAcceptRide.toString())) {
                                                                      showDialog(
                                                                        context: context,
                                                                        builder: (context) {
                                                                          return CustomDialogBox(
                                                                              title: "Confirm Parcel Request".tr,
                                                                              descriptions:
                                                                                  "Are you sure you want to accept this ride request? Once confirmed, you will be directed to the next step to proceed with the ride."
                                                                                      .tr,
                                                                              img: Image.asset(
                                                                                "assets/icon/ic_green_right.png",
                                                                                height: 58,
                                                                                width: 58,
                                                                              ),
                                                                              positiveClick: () async {
                                                                                if (Constant.isSubscriptionEnable == true) {
                                                                                  if (Constant.userModel!.subscriptionPlanId != null &&
                                                                                      Constant.userModel!.subscriptionPlanId!.isNotEmpty) {
                                                                                    if (Constant.userModel!.subscriptionTotalBookings == '0') {
                                                                                      Navigator.pop(context);
                                                                                      showDialog(
                                                                                          context: context,
                                                                                          builder: (context) {
                                                                                            return SubscriptionAlertDialog(
                                                                                              title: "You can't accept more Rides.Upgrade your Plan.".tr,
                                                                                              themeChange: themeChange,
                                                                                            );
                                                                                          });
                                                                                      // ShowToastDialog.showToast(
                                                                                      //     "You can't accept more Bookings.Upgrade your Plan.");
                                                                                      return;
                                                                                    }
                                                                                  }

                                                                                  if (Constant.userModel!.subscriptionExpiryDate != null &&
                                                                                      Constant.userModel!.subscriptionExpiryDate!.toDate().isBefore(DateTime.now())) {
                                                                                    Navigator.pop(context);
                                                                                    showDialog(
                                                                                        context: context,
                                                                                        builder: (context) {
                                                                                          return SubscriptionAlertDialog(
                                                                                            title: "Your subscription has expired. Please renew your plan.".tr,
                                                                                            themeChange: themeChange,
                                                                                          );
                                                                                        });
                                                                                    // ShowToastDialog.showToast(
                                                                                    //     "Your subscription has expired. Please renew your plan.");
                                                                                    return;
                                                                                  }
                                                                                }
                                                                                await FireStoreUtils.getVehicleTypeById(
                                                                                    Constant.userModel!.driverVehicleDetails!.vehicleTypeId.toString());
                                                                                parcelModel.driverVehicleDetails = Constant.userModel!.driverVehicleDetails;
                                                                                parcelModel.driverId = FireStoreUtils.getCurrentUid();
                                                                                parcelModel.bookingStatus = BookingStatus.bookingAccepted;
                                                                                parcelModel.updateAt = Timestamp.now();
                                                                                FireStoreUtils.setParcelBooking(parcelModel).then((value) async {
                                                                                  if (value == true) {
                                                                                    ShowToastDialog.showToast("Parcel accepted successfully!".tr);

                                                                                    UserModel? receiverUserModel =
                                                                                        await FireStoreUtils.getUserProfile(parcelModel.customerId.toString());
                                                                                    Map<String, dynamic> playLoad = <String, dynamic>{"bookingId": parcelModel.id};

                                                                                    await SendNotification.sendOneNotification(
                                                                                        type: "order",
                                                                                        token: receiverUserModel!.fcmToken.toString(),
                                                                                        title: 'Your Parcel is Accepted',
                                                                                        customerId: receiverUserModel.id,
                                                                                        senderId: FireStoreUtils.getCurrentUid(),
                                                                                        bookingId: parcelModel.id.toString(),
                                                                                        driverId: parcelModel.driverId.toString(),isBooking: false,
                                                                                        body: 'Your Parcel #${parcelModel.id.toString().substring(0, 5)} has been confirmed.',
                                                                                        payload: playLoad);
                                                                                    if (Constant.isSubscriptionEnable == true &&
                                                                                        Constant.userModel!.subscriptionPlanId != null &&
                                                                                        Constant.userModel!.subscriptionPlanId!.isNotEmpty &&
                                                                                        Constant.userModel!.subscriptionTotalBookings != '0' &&
                                                                                        Constant.userModel!.subscriptionTotalBookings != '-1' &&
                                                                                        Constant.userModel!.subscriptionTotalBookings != null) {
                                                                                      int remainingBookings = int.parse(Constant.userModel!.subscriptionTotalBookings!) - 1;
                                                                                      Constant.userModel!.subscriptionTotalBookings = remainingBookings.toString();
                                                                                      await FireStoreUtils.updateDriverUser(Constant.userModel!);
                                                                                    }
                                                                                    Navigator.pop(context);
                                                                                  } else {
                                                                                    ShowToastDialog.showToast("Something went wrong!".tr);
                                                                                    Navigator.pop(context);
                                                                                  }
                                                                                });
                                                                                Navigator.pop(context);
                                                                              },
                                                                              negativeClick: () {
                                                                                Navigator.pop(context);
                                                                              },
                                                                              positiveString: "Confirm".tr,
                                                                              negativeString: "Cancel".tr,
                                                                              themeChange: themeChange);
                                                                        },
                                                                      );
                                                                    } else {
                                                                      ShowToastDialog.showToast("minimumAmountToAcceptRide".trParams(
                                                                          {"minimumAmountToAcceptRide": Constant.amountShow(amount: Constant.minimumAmountToAcceptRide)}));

                                                                      // ShowToastDialog.showToast(
                                                                      //     "You do not have sufficient wallet balance to accept the ride, as the minimum amount required is ${Constant.amountShow(amount: Constant.minimumAmountToAcceptRide)}.");
                                                                    }
                                                                  },
                                                                  size: Size(Responsive.width(40, context), 42),
                                                                )
                                                              ],
                                                            )
                                                          : parcelModel.bookingStatus == BookingStatus.bookingAccepted
                                                              ? Row(
                                                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                                                  crossAxisAlignment: CrossAxisAlignment.center,
                                                                  children: [
                                                                    RoundShapeButton(
                                                                      title: "Cancel Ride".tr,
                                                                      buttonColor: themeChange.isDarkTheme() ? AppThemData.grey900 : AppThemData.grey50,
                                                                      buttonTextColor: themeChange.isDarkTheme() ? AppThemData.white : AppThemData.black,
                                                                      onTap: () {
                                                                        Get.to(() => ReasonForCancelParcelView(
                                                                              bookingInterCityModel: parcelModel,
                                                                            ));
                                                                      },
                                                                      size: Size(Responsive.width(40, context), 42),
                                                                    ),
                                                                    const SizedBox(width: 4),
                                                                    RoundShapeButton(
                                                                      title: "Pickup".tr,
                                                                      buttonColor: AppThemData.primary500,
                                                                      buttonTextColor: AppThemData.black,
                                                                      onTap: () {
                                                                        if (Constant.isOtpFeatureEnable == true) {
                                                                          Get.toNamed(Routes.ASK_FOR_OTP_PARCEL, arguments: {
                                                                            "bookingModel": parcelModel,
                                                                          });
                                                                        } else {
                                                                          showDialog(
                                                                              context: context,
                                                                              builder: (BuildContext context) {
                                                                                return CustomDialogBox(
                                                                                    themeChange: themeChange,
                                                                                    title: "Confirm Parcel Ride Request".tr,
                                                                                    descriptions:
                                                                                        "Are you sure you want to accept this ride request? Once confirmed, you will be directed to the next step to proceed with the ride."
                                                                                            .tr,
                                                                                    positiveString: "Confirm".tr,
                                                                                    negativeString: "Cancel".tr,
                                                                                    positiveClick: () async {
                                                                                      Navigator.pop(context);
                                                                                      parcelModel.bookingStatus = BookingStatus.bookingOngoing;
                                                                                      parcelModel.updateAt = Timestamp.now();
                                                                                      parcelModel.pickupTime = Timestamp.now();
                                                                                      await FireStoreUtils.setParcelBooking(parcelModel);
                                                                                      ShowToastDialog.showToast("Your parcel ride started....".tr);
                                                                                      UserModel? receiverUserModel =
                                                                                          await FireStoreUtils.getUserProfile(parcelModel.customerId.toString());
                                                                                      Map<String, dynamic> playLoad = <String, dynamic>{"bookingId": parcelModel.id};

                                                                                      await SendNotification.sendOneNotification(
                                                                                          type: "order",
                                                                                          token: receiverUserModel!.fcmToken.toString(),
                                                                                          title: 'Your Parcel Ride is Started',
                                                                                          customerId: receiverUserModel.id,isBooking: false,
                                                                                          senderId: FireStoreUtils.getCurrentUid(),
                                                                                          bookingId: parcelModel.id.toString(),
                                                                                          driverId: parcelModel.driverId.toString(),
                                                                                          body:
                                                                                              'Your Parcel Ride is Started From ${parcelModel.pickUpLocationAddress.toString()} to ${parcelModel.dropLocationAddress.toString()}.',
                                                                                          payload: playLoad);

                                                                                      Get.back();
                                                                                      Get.back();
                                                                                    },
                                                                                    negativeClick: () {
                                                                                      Navigator.pop(context);
                                                                                    },
                                                                                    img: Image.asset(
                                                                                      "assets/icon/ic_green_right.png",
                                                                                      height: 58,
                                                                                      width: 58,
                                                                                    ));
                                                                              });
                                                                        }
                                                                      },
                                                                      size: Size(Responsive.width(40, context), 42),
                                                                    )
                                                                  ],
                                                                )
                                                              : SizedBox()
                                                      : parcelModel.bookingStatus == BookingStatus.bookingPlaced
                                                          ? Expanded(
                                                              child: RoundShapeButton(
                                                                title: (parcelModel.driverBidIdList == null || parcelModel.driverBidIdList!.isEmpty)
                                                                    ? "Add Bid".tr
                                                                    : (parcelModel.driverBidIdList!.contains(FireStoreUtils.getCurrentUid()) ? "View Bid".tr : "Add Bid".tr),
                                                                buttonColor: AppThemData.primary500,
                                                                buttonTextColor: AppThemData.black,
                                                                onTap: () {
                                                                  Get.to(
                                                                    ParcelBookingDetailsView(),
                                                                    arguments: {
                                                                      "bookingId": parcelModel.id ?? '',
                                                                    },
                                                                  );
                                                                },
                                                                size: const Size(double.infinity, 48),
                                                              ),
                                                            )
                                                          : parcelModel.bookingStatus == BookingStatus.bookingAccepted
                                                              ? RoundShapeButton(
                                                                  title: "Cancel Ride".tr,
                                                                  buttonColor: AppThemData.danger500,
                                                                  buttonTextColor: AppThemData.white,
                                                                  onTap: () {
                                                                    Get.to(() => ReasonForCancelParcelView(
                                                                          bookingInterCityModel: parcelModel,
                                                                        ));
                                                                  },
                                                                  size: Size(Responsive.width(79, context), 42),
                                                                )
                                                              : SizedBox(),
                                                ],
                                              ),
                                              const SizedBox(height: 10),
                                            ],
                                          ),
                                        ),
                                      ),
                                    ],
                                  ),
                                ),
                              );
                            },
                          ),
                  ),
                ),
              ],
            ));
      },
    );
  }
}
