import 'dart:convert';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/app_strings/app_asset.dart';
import 'package:test_sa/dashboard_latest/widgets/request_category_list.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/models/enums/work_order_next_step.dart';
import 'package:test_sa/models/helper_data_models/maintenance_request/activity_maintenance_model.dart';
import 'package:test_sa/models/helper_data_models/spare_part/activity_spare_part_model.dart';
import 'package:test_sa/models/helper_data_models/workorder/work_order_helper_models.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart';
import 'package:test_sa/providers/service_request_providers/reject_reason_provider.dart';
import 'package:test_sa/service_request_latest/request_detail_provider.dart';
import 'package:test_sa/service_request_latest/views/forms/maintenance_request/maintenance_request_main.dart';
import 'package:test_sa/service_request_latest/views/forms/spare_part/spare_part_request.dart';
import 'package:test_sa/views/widgets/date_and_time/date_picker.dart';
import 'package:test_sa/views/widgets/e_signature/e_signature.dart';

import '../../../../controllers/providers/api/service_requests_provider.dart';
import '../../../../new_views/app_style/app_color.dart';
import '../../../../new_views/common_widgets/app_filled_button.dart';
import '../../../../new_views/common_widgets/app_text_form_field.dart';

class ServiceRequestBottomSheet {
  static buildBottomSheetParent({required BuildContext context, required Widget childWidget}) {
    return showModalBottomSheet(
      context: context,
      useSafeArea: true,
      isScrollControlled: true,
      backgroundColor: Colors.transparent,
      builder: (context) => SingleChildScrollView(
        child: childWidget,
      ).bottomSheetContainer(context),
    );
  }

  static Future fixRemotelyBottomSheet({required BuildContext context}) {
    TextEditingController _workingHoursController = TextEditingController();
    int calculateWorkingHours(DateTime? startTime, DateTime? endTime) {
      if (startTime != null && endTime != null) {
        Duration difference = endTime.difference(startTime);
        int hours = difference.inHours;
        return hours;
      } else {
        return -1;
      }
    }

    assignWorkingHours({required RequestDetailProvider requestDetailProvider}) {
      int hours = calculateWorkingHours(requestDetailProvider.fixRemotelyHelperModel?.startDate, requestDetailProvider.fixRemotelyHelperModel?.endDate);
      if (hours != -1) {
        _workingHoursController.text = hours.toString();
        requestDetailProvider.fixRemotelyHelperModel?.workingHour = hours;
      }
    }

    return buildBottomSheetParent(
        context: context,
        childWidget: Consumer<RequestDetailProvider>(builder: (context, RequestDetailProvider requestDetailProvider, child) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              const SizedBox().indicatorWidget(),
              16.height,
              Align(
                alignment: AlignmentDirectional.centerStart,
                child: context.translation.fillDetails.bottomSheetHeadingTextStyle(context),
              ),
              16.height,
              ADatePicker(
                label: context.translation.startDate,
                hideShadow: true,
                // height: 60.toScreenHeight,
                backgroundColor: AppColor.neutral100,
                date: requestDetailProvider.fixRemotelyHelperModel?.startDate,
                formatDateWithTime: true,
                onDatePicker: (selectedDate) {
                  showTimePicker(
                    context: context,
                    initialTime: TimeOfDay.now(),
                  ).then((selectedTime) {
                    // Handle the selected date and time here.
                    if (selectedTime != null) {
                      DateTime selectedDateTime = DateTime(
                        selectedDate.year,
                        selectedDate.month,
                        selectedDate.day,
                        selectedTime.hour,
                        selectedTime.minute,
                      );

                      requestDetailProvider.fixRemotelyHelperModel?.startDate = selectedDateTime;
                      requestDetailProvider.updateFixRemotelyHelperModel(requestDetailProvider.fixRemotelyHelperModel);
                      assignWorkingHours(requestDetailProvider: requestDetailProvider);
                      // serviceRequestProvider.updateCurrentSelectedRequest(serviceRequestProvider.currentSelectedRequest);
                    }
                  });
                },
              ),
              8.height,
              ADatePicker(
                label: context.translation.endDate,
                hideShadow: true,
                // height: 60.toScreenHeight,
                backgroundColor: AppColor.neutral100,
                date: requestDetailProvider.fixRemotelyHelperModel?.endDate,
                formatDateWithTime: true,
                onDatePicker: (selectedDate) {
                  showTimePicker(
                    context: context,
                    initialTime: TimeOfDay.now(),
                  ).then((selectedTime) {
                    // Handle the selected date and time here.
                    if (selectedTime != null) {
                      DateTime selectedDateTime = DateTime(
                        selectedDate.year,
                        selectedDate.month,
                        selectedDate.day,
                        selectedTime.hour,
                        selectedTime.minute,
                      );

                      if (requestDetailProvider.fixRemotelyHelperModel!.startDate != null && selectedDateTime.isBefore(requestDetailProvider.fixRemotelyHelperModel!.startDate!)) {
                        "End Date time must be greater then start date".showToast;
                        return;
                      }

                      requestDetailProvider.fixRemotelyHelperModel?.endDate = selectedDateTime;
                      requestDetailProvider.updateFixRemotelyHelperModel(requestDetailProvider.fixRemotelyHelperModel);
                      assignWorkingHours(requestDetailProvider: requestDetailProvider);

                      // serviceRequestProvider.updateCurrentSelectedRequest(serviceRequestProvider.currentSelectedRequest);
                    }
                  });
                },
              ),
              8.height,
              AppTextFormField(
                labelText: context.translation.workingHours,
                textInputType: TextInputType.number,
                enable: false,
                controller: _workingHoursController,
                labelStyle: AppTextStyles.textFieldLabelStyle,
                showWithoutDecoration: true,
                backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100,
                alignLabelWithHint: true,
                onChange: (text) {
                  if (text.isNotEmpty) {
                    requestDetailProvider.fixRemotelyHelperModel?.workingHour = int.parse(text);
                  }
                },
                onSaved: (text) {
                  if (text.isNotEmpty) {
                    requestDetailProvider.fixRemotelyHelperModel?.workingHour = int.parse(text);
                  }
                },
              ),
              8.height,
              AppTextFormField(
                labelText: context.translation.comments,
                textInputType: TextInputType.multiline,
                labelStyle: AppTextStyles.textFieldLabelStyle,
                showWithoutDecoration: true,
                backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100,
                alignLabelWithHint: true,
                onChange: (text) {
                  requestDetailProvider.fixRemotelyHelperModel?.comment = text;
                },
                onSaved: (text) {
                  requestDetailProvider.fixRemotelyHelperModel?.comment = text;
                },
              ),
              16.height,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  SizedBox(
                    width: 200.toScreenHeight,
                    child: AppFilledButton(
                      label: context.translation.cancel,
                      loading: false,
                      buttonColor: Colors.transparent,
                      showBorder: true,
                      textColor: AppColor.black20,
                      onPressed: () async {
                        Navigator.pop(context);
                      },
                    ),
                  ),
                  SizedBox(
                    width: 200.toScreenHeight,
                    child: AppFilledButton(
                      label: context.translation.fixed,
                      buttonColor: AppColor.green70,
                      loading: false,
                      onPressed: () async {
                        requestDetailProvider.fixRemotelyHelperModel?.workOrderId = requestDetailProvider.currentWorkOrder?.data?.requestId;
                        requestDetailProvider.engineerFixRemotely();
                        //TODO context issue to show message..
                        Navigator.pop(context);
                        // const  SizedBox().flushBar(context: context, title: '', message: context.translation.youMarkedThisIssueAsFixedWaitingForTheRequesterToConfirm);
                      },
                    ),
                  ),
                ],
              ),
              16.height,
            ],
          );
        }));
  }

  static Future initialVisitBottomSheet({required BuildContext context}) {
    TextEditingController _commentController = TextEditingController();

    return buildBottomSheetParent(
        context: context,
        childWidget: Consumer<RequestDetailProvider>(builder: (context, requestDetailProvider, child) {
          if (requestDetailProvider.needVisitHelperModel?.comment != null) {
            _commentController.text = requestDetailProvider.needVisitHelperModel!.comment!;
          }
          return Column(
            children: [
              const SizedBox().indicatorWidget(),
              8.height,
              Align(
                alignment: AlignmentDirectional.centerStart,
                child: context.translation.setVisitDate.bottomSheetHeadingTextStyle(context),
              ),
              15.height,
              ADatePicker(
                label: context.translation.visitDate,
                hideShadow: true,
                backgroundColor: AppColor.neutral100,
                date: requestDetailProvider.needVisitHelperModel?.visitDate,
                formatDateWithTime: true,
                onDatePicker: (selectedDate) {
                  if (selectedDate != null) {
                    showTimePicker(
                      context: context,
                      initialTime: TimeOfDay.now(),
                    ).then((selectedTime) {
                      // Handle the selected date and time here.
                      if (selectedTime != null) {
                        DateTime selectedDateTime = DateTime(
                          selectedDate.year,
                          selectedDate.month,
                          selectedDate.day,
                          selectedTime.hour,
                          selectedTime.minute,
                        );
                        requestDetailProvider.needVisitHelperModel?.visitDate = selectedDateTime;
                        requestDetailProvider.updateNeedVisitHelperModel(requestDetailProvider.needVisitHelperModel);
                      }
                    });
                  }
                },
              ),
              8.height,
              AppTextFormField(
                labelText: context.translation.comments,
                controller: _commentController,
                backgroundColor: AppColor.neutral100,
                labelStyle: AppTextStyles.textFieldLabelStyle,
                showShadow: false,
                textInputType: TextInputType.multiline,
                alignLabelWithHint: true,
                onChange: (text) {
                  requestDetailProvider.needVisitHelperModel?.comment = text;
                },
                onSaved: (text) {
                  requestDetailProvider.needVisitHelperModel?.comment = text;
                },
              ),
              12.height,
              AppFilledButton(
                label: context.translation.save,
                buttonColor: AppColor.primary10,
                loading: false,
                onPressed: () async {
                  if (requestDetailProvider.currentWorkOrder?.data?.nextStep!.workOrderNextStepEnum == WorkOrderNextStepEnum.eArrived) {
                    requestDetailProvider.updateNeedVisitHelperModel(NeedVisitHelperModel(
                      workOrderId: requestDetailProvider.needVisitHelperModel?.workOrderId,
                      visitDate: requestDetailProvider.needVisitHelperModel?.visitDate,
                      comment: requestDetailProvider.needVisitHelperModel?.comment,
                    ));
                    requestDetailProvider.engineerUpdateNeedVisit();
                  } else {
                    requestDetailProvider.needVisitHelperModel?.workOrderId = requestDetailProvider.currentWorkOrder!.data!.requestId;
                    requestDetailProvider.engineerNeedVisit();
                    requestDetailProvider.needVisitHelperModel = NeedVisitHelperModel();
                  }
                  Navigator.pop(context);
                },
              ),
              16.height,
            ],
          );
        }));
  }

  static Future rejectRequestBottomSheet({required BuildContext context}) {
    return buildBottomSheetParent(
        context: context,
        childWidget: Consumer<RequestDetailProvider>(builder: (context, requestDetailProvider, child) {
          return Column(
            children: [
              const SizedBox().indicatorWidget(),
              Align(
                alignment: AlignmentDirectional.centerStart,
                child: context.translation.rejectionReason.heading4(context).paddingOnly(top: 12),
              ),
              16.height,
              SingleItemDropDownMenu<Lookup, RejectReasonProvider>(
                context: context,
                title: context.translation.reason,
                backgroundColor: AppColor.neutral100,
                showShadow: false,
                initialValue: requestDetailProvider.engineerRejectHelperModel?.rejectionReason,
                onSelect: (value) {
                  if (value != null) {
                    requestDetailProvider.engineerRejectHelperModel?.rejectionReason = value;
                    requestDetailProvider.updateEngineerRejectHelperModel(requestDetailProvider.engineerRejectHelperModel);
                  }
                },
              ),
              12.height,
              AppTextFormField(
                backgroundColor: AppColor.neutral100,
                labelText: context.translation.comments,
                textInputType: TextInputType.multiline,
                alignLabelWithHint: true,
                showShadow: false,
                labelStyle: AppTextStyles.textFieldLabelStyle,
                onChange: (text) {
                  requestDetailProvider.engineerRejectHelperModel?.feedback = text;
                },
                onSaved: (text) {
                  requestDetailProvider.engineerRejectHelperModel?.feedback = text;
                  requestDetailProvider.updateEngineerRejectHelperModel(requestDetailProvider.engineerRejectHelperModel);
                },
              ),
              16.height,
              AppFilledButton(
                label: context.translation.reject,
                maxWidth: true,
                buttonColor: Colors.white54,
                textColor: AppColor.red30,
                showBorder: true,
                loading: requestDetailProvider.isLoading,
                onPressed: () async {
                  requestDetailProvider.engineerRejectHelperModel?.workOrderId = requestDetailProvider.currentWorkOrder?.data?.requestId;
                  requestDetailProvider.engineerRejectWorkOrder();
                  Navigator.pop(context, true);
                },
              ),
              16.height,
            ],
          );
        }));
  }

  static Future activityTypeBottomSheet({required BuildContext context}) {
    final List<Map<String, String>> items = [
      {'heading': context.translation.sparePartRequest, 'subHeading': context.translation.sparePartRequestDetail, 'icon': AppAsset.sparePartIcon},
      {'heading': context.translation.maintenanceRequest, 'subHeading': context.translation.sparePartRequestDetail, 'icon': AppAsset.maintenanceIcon},
    ];
    Widget customListItem({
      required BuildContext context,
      required String icon,
      required String heading,
      required String subHeading,
      required VoidCallback onTap,
    }) {
      return GestureDetector(
        onTap: onTap, // Handles the tap
        child: Card(
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(14), // Circular border radius
          ),
          color: AppColor.neutral80,
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start, // Align items at the top
            children: [
              // Icon Section
              icon
                  .toSvgAsset(
                    width: 26,
                    color: AppColor.neutral120,
                    height: 29,
                  )
                  .paddingOnly(top: 8),
              14.width,
              Expanded(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    Text(
                      heading,
                      style: AppTextStyles.heading6.copyWith(color: AppColor.neutral50),
                    ),
                    7.height,
                    Text(
                      subHeading,
                      style: AppTextStyles.bodyText2.copyWith(color: AppColor.neutral120),
                    ),
                  ],
                ).paddingOnly(end: 50),
              ),
            ],
          ).paddingAll(12),
        ),
      );
    }

    void onItemTap({required int index, required BuildContext context}) {
      switch (index) {
        case 0:
          Provider.of<RequestDetailProvider>(context, listen: false).sparePartHelperModel = SparePartHelperModel();
          Navigator.pushReplacement(
            context,
            MaterialPageRoute(builder: (context) => const SparePartRequest()),
          );
          break;
        case 1:
          RequestDetailProvider requestDetailProvider = Provider.of<RequestDetailProvider>(context, listen: false);
          requestDetailProvider.activityMaintenanceHelperModel = ActivityMaintenanceHelperModel(
            workOrderId: requestDetailProvider.currentWorkOrder?.data?.requestId,
            id: 0,
            assignedEmployee: requestDetailProvider.currentWorkOrder?.data?.assignedEmployee,
          );
          Navigator.pushReplacement(
            context,
            MaterialPageRoute(builder: (context) => const MaintenanceRequestForm()),
          );
          break;
      }
    }

    return buildBottomSheetParent(
        context: context,
        childWidget: Consumer<ServiceRequestsProvider>(builder: (context, serviceRequestProvider, child) {
          return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const SizedBox().indicatorWidget(),
              8.height,
              Align(
                alignment: AlignmentDirectional.centerStart,
                child: context.translation.selectActivityType.bottomSheetHeadingTextStyle(context),
              ),
              16.height,
              ListView.builder(
                shrinkWrap: true,
                padding: EdgeInsets.zero,
                itemCount: items.length,
                itemBuilder: (context, index) {
                  final item = items[index];
                  return customListItem(
                      icon: item['icon']!,
                      heading: item['heading']!,
                      subHeading: item['subHeading']!,
                      context: context,
                      onTap: () {
                        onItemTap(index: index, context: context);
                      });
                },
              ),
            ],
          );
        }));
  }

  static Future actionBottomSheet({required BuildContext context, required String title, String? button1Text, String? button2Text, VoidCallback? button1Tap, VoidCallback? button2Tap}) {
    return buildBottomSheetParent(
        context: context,
        childWidget: Consumer<ServiceRequestsProvider>(builder: (context, serviceRequestProvider, child) {
          return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const SizedBox().indicatorWidget(),
              8.height,
              Align(
                alignment: AlignmentDirectional.centerStart,
                child: title.bottomSheetHeadingTextStyle(context),
              ),
              41.height,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  AppFilledButton(
                    label: button1Text ?? context.translation.no,
                    loading: false,
                    buttonColor: AppColor.white60,
                    textColor: AppColor.black10,
                    onPressed: button1Tap ??
                        () async {
                          Navigator.pop(context);
                        },
                  ).expanded,
                  12.width,
                  AppFilledButton(
                    label: context.translation.yes,
                    buttonColor: AppColor.primary10,
                    loading: false,
                    onPressed: button2Tap,
                  ).expanded,
                ],
              )
            ],
          );
        }));
  }

  static Future addAnotherSpareRequestBottomSheet({required BuildContext context}) {
    return buildBottomSheetParent(
      context: context,
      childWidget: Consumer<ServiceRequestsProvider>(
        builder: (context, serviceRequestProvider, child) {
          return Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              const SizedBox().indicatorWidget(),
              8.height,
              Align(
                alignment: AlignmentDirectional.centerStart,
                child: context.translation.doYouWantToCreateAnotherSparePartRequest.bottomSheetHeadingTextStyle(context),
              ),
              41.height,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  AppFilledButton(
                    label: context.translation.no,
                    loading: false,
                    buttonColor: AppColor.white60,
                    textColor: AppColor.black10,
                    onPressed: () async {
                      Navigator.pop(context);
                    },
                  ).expanded,
                  12.width,
                  AppFilledButton(
                    label: context.translation.yes,
                    buttonColor: AppColor.primary10,
                    loading: false,
                    onPressed: () {
                      Provider.of<RequestDetailProvider>(context, listen: false).sparePartHelperModel = SparePartHelperModel();
                      Navigator.pushReplacement(
                        context,
                        MaterialPageRoute(builder: (context) => const SparePartRequest()),
                      );
                    },
                  ).expanded,
                ],
              ),
              16.height,
            ],
          );
        },
      ),
    );
  }

  static Future feedBackBottomSheet({required BuildContext context}) {
    String feedback = '';
    return buildBottomSheetParent(
        context: context,
        childWidget: Consumer<RequestDetailProvider>(builder: (context, RequestDetailProvider requestDetailProvider, child) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              const SizedBox().indicatorWidget(),
              8.height,
              Align(
                alignment: AlignmentDirectional.centerStart,
                child: context.translation.feedBack.bottomSheetHeadingTextStyle(context),
              ),
              21.height,
              AppTextFormField(
                labelText: context.translation.comments,
                textInputType: TextInputType.multiline,
                labelStyle: AppTextStyles.textFieldLabelStyle,
                showWithoutDecoration: true,
                backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100,
                alignLabelWithHint: true,
                onChange: (text) {
                  feedback = text;
                },
                onSaved: (text) {
                  feedback = text;
                },
              ),
              16.height,
              AppFilledButton(
                label: context.translation.fixed,
                buttonColor: AppColor.green70,
                loading: false,
                onPressed: () {
                  Navigator.pop(context);
                  requestDetailProvider.engineerMarkAsFixed(workOrderId: requestDetailProvider.currentWorkOrder!.data!.requestId!, feedback: feedback);
                },
              ),
            ],
          );
        }));
  }
  static Future nurseRejectBackBottomSheet({required BuildContext context}) {
    String feedback = '';
    return buildBottomSheetParent(
        context: context,
        childWidget: Consumer<RequestDetailProvider>(builder: (context, RequestDetailProvider requestDetailProvider, child) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              const SizedBox().indicatorWidget(),
              8.height,
              Align(
                alignment: AlignmentDirectional.centerStart,
                child: context.translation.rejectionReason.bottomSheetHeadingTextStyle(context),
              ),
              21.height,
              AppTextFormField(
                labelText: context.translation.comments,
                textInputType: TextInputType.multiline,
                labelStyle: AppTextStyles.textFieldLabelStyle,
                showWithoutDecoration: true,
                backgroundColor: context.isDark ? AppColor.neutral20 : AppColor.neutral100,
                alignLabelWithHint: true,
                onChange: (text) {
                  feedback = text;
                },
                onSaved: (text) {
                  feedback = text;
                },
              ),
              16.height,
              AppFilledButton(
                label: context.translation.reject,
                maxWidth: true,
                buttonColor: Colors.white54,
                textColor: AppColor.red30,
                showBorder: true,
                onPressed: () {
                  if (feedback.isNotEmpty) {
                    requestDetailProvider.nurseActionHelperModel = NurseActionHelperModel(
                      workOrderId: requestDetailProvider.currentWorkOrder!.data!.requestId,
                      feedback: feedback,
                    );
                    requestDetailProvider.nurseReject();
                    Navigator.pop(context);
                    if(requestDetailProvider.currentWorkOrder!.data!.requestId!=null){
                      requestDetailProvider.getWorkOrderById(id: requestDetailProvider.currentWorkOrder!.data!.requestId!);
                    }
                  }
                  // Navigator.pop(context);
                  // requestDetailProvider.engineerMarkAsFixed(workOrderId: requestDetailProvider.currentWorkOrder!.data!.requestId!, feedback: feedback);
                },
              ),
            ],
          );
        }));
  }

  static Future nurseTakeActionBottomSheet({required BuildContext context}) {
    bool acknowledge = false;
    Uint8List? newSignature;
    String? nurseSignature;
    return buildBottomSheetParent(
        context: context,
        childWidget: Consumer<RequestDetailProvider>(builder: (context, RequestDetailProvider requestDetailProvider, child) {
          return Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              const SizedBox().indicatorWidget(),
              8.height,
              Align(
                alignment: AlignmentDirectional.centerStart,
                child: context.translation.pleaseConfirmTheIssueHasBeenResolved.bottomSheetHeadingTextStyle(context),
              ),
              10.height,
              StatefulBuilder(
                builder: (context, setState) {
                  return Column(
                    children: [
                      Row(
                        children: [
                          InkWell(
                            child: acknowledge
                                ? const Icon(
                              Icons.check_box,
                              color: AppColor.primary10,
                            )
                                : const Icon(
                              Icons.check_box_outline_blank,
                              color: AppColor.neutral120,
                            ),
                            onTap: () {
                              setState(() {
                                acknowledge = !acknowledge;
                              });
                            },
                          ),
                          6.width,
                          Flexible(
                            child: context.translation.nurseAcknowledge
                                .bodyText(context)
                                .custom(color: context.isDark ? AppColor.primary50 : AppColor.neutral120),
                          ),
                        ],
                      ),
                      17.height,
                      ESignature(
                        title: '',
                        oldSignature: '',
                        newSignature: newSignature,
                        backgroundColor: AppColor.neutral100,
                        showShadow: false,
                        onChange:(signature){
                          setState(() {
                            if (signature == null || signature.isEmpty) return;
                            newSignature = signature;
                            nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}";
                            print('signature i got is ${newSignature}');
                          });
                  },
                        onSaved: (signature) {

                          setState(() {
                            if (signature == null || signature.isEmpty) return;
                            newSignature = signature;
                            nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}";
                            print('signature i got is ${newSignature}');
                          });
                        },
                      ),
                    ],
                  );
                },
              ),
              36.height,
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                mainAxisSize: MainAxisSize.min,
                children: [
                  AppFilledButton(
                    label: context.translation.reject,
                    maxWidth: true,
                    buttonColor: Colors.white54,
                    textColor: AppColor.red30,
                    showBorder: true,
                    onPressed: () async {
                      Navigator.pop(context);
                      nurseRejectBackBottomSheet(context: context);
                    },
                  ).expanded,
                  const SizedBox(
                    width: 20,
                  ),
                  AppFilledButton(
                    label: context.translation.confirm,
                    maxWidth: true,
                    buttonColor: AppColor.green70,
                    onPressed: () async {
                      if (newSignature != null) {
                        requestDetailProvider.nurseActionHelperModel = NurseActionHelperModel(
                          workOrderId: requestDetailProvider.currentWorkOrder!.data!.requestId!,
                          signatureNurse: nurseSignature,
                        );
                        requestDetailProvider.nurseConfirm();
                        if(requestDetailProvider.currentWorkOrder!.data!.requestId!=null){
                          requestDetailProvider.getWorkOrderById(id: requestDetailProvider.currentWorkOrder!.data!.requestId!);
                        }
                        Navigator.pop(context);
                      }else{
                        //show some toast...
                      }
                    },
                  ).expanded,
                ],
              )
            ],
          );
        }));

    //
    // return showModalBottomSheet(
    //     context: context,
    //     useSafeArea: true,
    //     isScrollControlled: true,
    //     backgroundColor: Colors.transparent,
    //     builder: (context) => Consumer<ServiceRequestsProvider>(builder: (context, serviceRequestProvider, child) {
    //           return Form(
    //             key: _formKey,
    //             child: SingleChildScrollView(
    //               child: StatefulBuilder(builder: (context, setState) {
    //                 return Column(
    //                   crossAxisAlignment: CrossAxisAlignment.center,
    //                   children: [
    //                     const SizedBox().indicatorWidget(),
    //                     8.height,
    //                     Align(
    //                       alignment: AlignmentDirectional.centerStart,
    //                       child: context.translation.pleaseConfirmTheIssueHasBeenResolved.bottomSheetHeadingTextStyle(context),
    //                     ),
    //                     10.height,
    //                     Row(
    //                       children: [
    //                         InkWell(
    //                           child: acknowledge
    //                               ? const Icon(
    //                                   Icons.check_box,
    //                                   color: AppColor.primary10,
    //                                 )
    //                               : const Icon(
    //                                   Icons.check_box_outline_blank,
    //                                   color: AppColor.neutral120,
    //                                 ),
    //                           onTap: () {
    //                             setState(() {
    //                               acknowledge = !acknowledge;
    //                             });
    //                           },
    //                         ),
    //                         6.width,
    //                         Flexible(child: context.translation.nurseAcknowledge.bodyText(context).custom(color: context.isDark ? AppColor.primary50 : AppColor.neutral120)),
    //                       ],
    //                     ),
    //                     17.height,
    //                     ESignature(
    //                       title: '',
    //                       oldSignature: '',
    //                       newSignature: newSignature,
    //                       backgroundColor: AppColor.neutral100,
    //                       showShadow: false,
    //                       onSaved: (signature) {
    //                         if (signature == null || signature.isEmpty) return;
    //                         newSignature = signature;
    //                         nurseSignature = "${DateTime.now().toIso8601String()}.png|${base64Encode(signature)}";
    //                       },
    //                     ),
    //                     36.height,
    //                     Row(
    //                       mainAxisAlignment: MainAxisAlignment.spaceBetween,
    //                       mainAxisSize: MainAxisSize.min,
    //                       children: [
    //                         AppFilledButton(
    //                           label: context.translation.reject,
    //                           maxWidth: true,
    //                           buttonColor: Colors.white54,
    //                           textColor: AppColor.red30,
    //                           showBorder: true,
    //                           onPressed: () async {
    //                             _formKey.currentState?.save();
    //                             if (newSignature != null && acknowledge) {
    //                               //TODO replace provider with new provider and also check workorder id is not correct.
    //                               Provider.of<RequestDetailProvider>(context, listen: false).nurseReject(
    //                                   model: NurseActionModel(
    //                                 workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!),
    //                                 signatureNurse: nurseSignature,
    //                               ));
    //                               Navigator.pop(context);
    //                             }
    //                           },
    //                         ).expanded,
    //                         const SizedBox(
    //                           width: 20,
    //                         ),
    //                         AppFilledButton(
    //                           label: context.translation.confirm,
    //                           maxWidth: true,
    //                           buttonColor: AppColor.green70,
    //                           onPressed: () async {
    //                             _formKey.currentState?.save();
    //                             if (newSignature != null && acknowledge) {
    //                               //TODO replace provider with new provider and also check workorder id is not correct.
    //                               Provider.of<RequestDetailProvider>(context, listen: false).nurseConfirm(
    //                                   model: NurseActionModel(
    //                                 workOrderId: int.parse(serviceRequestProvider.currentSelectedRequest!.id!),
    //                                 signatureNurse: nurseSignature,
    //                               ));
    //                               Navigator.pop(context);
    //                             }
    //                           },
    //                         ).expanded,
    //                       ],
    //                     )
    //                   ],
    //                 );
    //               }),
    //             ),
    //           ).bottomSheetContainer(context);
    //         }));
  }
}
