import 'package:auto_size_text/auto_size_text.dart';
import 'package:hmg_patient_app/config/config.dart';
import 'package:hmg_patient_app/config/shared_pref_kay.dart';
import 'package:hmg_patient_app/config/size_config.dart';
import 'package:hmg_patient_app/core/model/hospitals/hospitals_model.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/models/Appointments/DoctorListResponse.dart';
import 'package:hmg_patient_app/models/Appointments/SearchInfoModel.dart';
import 'package:hmg_patient_app/models/Authentication/authenticated_user.dart';
import 'package:hmg_patient_app/models/Clinics/ClinicListResponse.dart';
import 'package:hmg_patient_app/pages/BookAppointment/DentalComplaints.dart';
import 'package:hmg_patient_app/pages/BookAppointment/LaserBooking.dart';
import 'package:hmg_patient_app/pages/BookAppointment/SearchResults.dart';
import 'package:hmg_patient_app/pages/BookAppointment/dialog/clinic_list_dialog.dart';
import 'package:hmg_patient_app/pages/BookAppointment/search_result/SearchResultWithTab.dart';
import 'package:hmg_patient_app/pages/livecare/livecare_home.dart';
import 'package:hmg_patient_app/services/appointment_services/GetDoctorsList.dart';
import 'package:hmg_patient_app/services/appointment_services/doctor_response_mapper.dart';
import 'package:hmg_patient_app/services/authentication/auth_provider.dart';
import 'package:hmg_patient_app/services/clinic_services/get_clinic_service.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/app_toast.dart';
import 'package:hmg_patient_app/uitl/gif_loader_dialog_utils.dart';
import 'package:hmg_patient_app/uitl/location_util.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:hmg_patient_app/widgets/card/rounded_container.dart';
import 'package:hmg_patient_app/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'LaserClinic.dart';
import 'LiveCareBookAppointment.dart';

class SearchByClinic extends StatefulWidget {
  final List? clnicIds;

  SearchByClinic({required this.clnicIds});

  @override
  _SearchByClinicState createState() => _SearchByClinicState();
}

class _SearchByClinicState extends State<SearchByClinic> {
  bool nearestAppo = false;
  String? dropdownValue;
  String dropdownTitle = "";
  String? projectDropdownValue;

  // var event = RobotProvider();
  List<ListClinicCentralized> clinicsList = [];
  List<HospitalsModel> projectsList = [];
  bool isMobileAppDentalAllow = false;
  bool isLoaded = false;
  bool isProjectLoaded = false;

  ListClinicCentralized? selectedClinic;
  HospitalsModel? selectedHospital;

  AuthenticatedUser authUser = new AuthenticatedUser();
  AuthProvider authProvider = new AuthProvider();

  final GlobalKey clinicDropdownKey = GlobalKey();
  final GlobalKey projectDropdownKey = GlobalKey();
  TextEditingController ageController = new TextEditingController();

  String radioValue = "";

  late LocationUtils locationUtils;

  @override
  void initState() {
    locationUtils = new LocationUtils(isShowConfirmDialog: true, isShowLocationTimeoutDialog: false, context: context);
    WidgetsBinding.instance.addPostFrameCallback((_) => getClinicsList());
    checkPVM();
    super.initState();
  }

  void checkPVM() {
    if (context.read<ProjectViewModel>().isLogin) {
      if (radioValue == null) {
        if (context.read<ProjectViewModel>().user.gender == 1) {
          radioValue = TranslationBase.of(context).male;
        } else {
          radioValue = TranslationBase.of(context).female;
        }
      }
    } else if (radioValue == null) {
      radioValue = TranslationBase.of(context).female;
    }
    if (ageController.text.isEmpty) {
      ageController.text = context.read<ProjectViewModel>().isLogin ? context.read<ProjectViewModel>().user!.age.toString() : "";
      ageController.selection = TextSelection.fromPosition(TextPosition(offset: ageController.text.length));
    }
  }

  @override
  Widget build(BuildContext context) {
    AppGlobal.context = context;
    return Container(
      child: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            if (context.read<ProjectViewModel>().isLogin)
              Column(
                children: [
                  Padding(
                    padding: const EdgeInsets.only(
                      left: 20,
                      right: 20,
                      top: 20,
                    ),
                    child: Text(
                      TranslationBase.of(context).doctorFilter,
                      style: TextStyle(
                        fontSize: 16,
                        fontWeight: FontWeight.w600,
                        letterSpacing: -0.64,
                      ),
                    ),
                  ),
                  mHeight(30),
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Padding(
                        padding: const EdgeInsets.only(left: 20, right: 20),
                        child: Text(
                          TranslationBase.of(context).gender,
                          style: TextStyle(
                            fontSize: 12,
                            letterSpacing: -0.48,
                            color: Colors.black,
                            fontWeight: FontWeight.w600,
                          ),
                        ),
                      ),
                      Container(
                        padding: EdgeInsets.only(left: 6, right: 6),
                        child: Row(
                          children: [
                            Flexible(
                                child: Row(
                              children: [
                                Radio(
                                  value: TranslationBase.of(context).female,
                                  groupValue: radioValue,
                                  onChanged: (v) {
                                    setState(() {
                                      radioValue = v!;
                                    });
                                  },
                                ),
                                Text(
                                  TranslationBase.of(context).female,
                                  style: TextStyle(
                                    fontSize: 12,
                                    letterSpacing: -0.48,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                              ],
                            )),
                            Flexible(
                                child: Row(
                              children: [
                                Radio(
                                  value: TranslationBase.of(context).male,
                                  groupValue: radioValue,
                                  onChanged: (v) {
                                    setState(() {
                                      radioValue = v!;
                                    });
                                  },
                                ),
                                Text(
                                  TranslationBase.of(context).male,
                                  style: TextStyle(
                                    fontSize: 12,
                                    letterSpacing: -0.48,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                              ],
                            )),
                          ],
                        ),
                      ),
                    ],
                  ),
                  Container(
                    child: inputWidget("Age", "", ageController),
                    margin: EdgeInsets.only(left: 20, right: 20),
                  ),
                ],
              ),
            Padding(
              padding: const EdgeInsets.only(left: 6, right: 6, top: 16),
              child: Row(
                children: <Widget>[
                  Checkbox(
                    activeColor: CustomColors.accentColor,
                    value: nearestAppo,
                    onChanged: (bool? value) {
                      setState(() {
                        nearestAppo = value!;
                        if (nearestAppo)
                          getProjectsList();
                        else
                          isProjectLoaded = false;
                      });
                    },
                  ),
                  AutoSizeText(
                    TranslationBase.of(context).nearestAppo.trim(),
                    maxLines: 1,
                    minFontSize: 10,
                    style: TextStyle(
                      fontSize: SizeConfig.textMultiplier! * 1.4,
                      fontWeight: FontWeight.w600,
                      letterSpacing: -0.39,
                      height: 0.8,
                    ),
                  ),
                  // Text(TranslationBase.of(context).nearestAppo, style: TextStyle(fontSize: 14.0, letterSpacing: -0.56)),
                ],
              ),
            ),
            widget.clnicIds != null && widget.clnicIds!.length > 1 && isLoaded == true
                ? Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: clinicsList.map<Widget>((result) {
                      return RoundedContainer(
                          child: ListTile(
                              onTap: () {
                                // setState(() {
                                dropdownValue = result.clinicID.toString();
                                setState(() {
                                  if (!isDentalSelectedAndSupported()) {
                                    dropdownValue = "";
                                    projectDropdownValue = "";
                                    getDoctorsList(context);
                                  } else {}
                                });
                              },
                              title: Text(result.clinicDescription!, style: TextStyle(fontSize: 14.0, color: Colors.grey[700], letterSpacing: 1.0))));
                    }).toList())
                : InkWell(
                    onTap: () {
                      showClickListDialog(context, clinicsList, onSelection: (ListClinicCentralized clincs) {
                        selectedClinic = clincs;
                        Navigator.pop(context);
                        setState(() {
                          dropdownTitle = clincs.clinicDescription!;
                          dropdownValue =
                              clincs.clinicID.toString() + "-" + clincs.isLiveCareClinicAndOnline.toString() + "-" + clincs.liveCareClinicID.toString() + "-" + clincs.liveCareServiceID.toString();
                          if (dropdownValue == "253-false-0-0") {
                            // Navigator.push(context, FadePage(page: LaserClinic()));
                          } else if (!isDentalSelectedAndSupported()) {
                            projectDropdownValue = "";
                            if (!nearestAppo) getDoctorsList(context);
                          } else {}
                        });
                        context.read<ProjectViewModel>().analytics.appointment.book_appointment_select_clinic(appointment_type: 'regular', clinic: clincs.clinicDescription);
                      });
                    },
                    child: Container(
                      width: double.infinity,
                      decoration: containerRadius(Colors.white, 12),
                      margin: EdgeInsets.only(left: 20, right: 20),
                      padding: EdgeInsets.only(left: 10, right: 10, top: 12, bottom: 8),
                      child: Row(
                        children: [
                          Expanded(
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  TranslationBase.of(context).selectClinic,
                                  style: TextStyle(
                                    fontSize: 11,
                                    letterSpacing: -0.44,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                                Padding(
                                  padding: const EdgeInsets.only(top: 4, bottom: 2),
                                  child: Text(
                                    dropdownTitle,
                                    style: TextStyle(
                                      fontSize: 13,
                                      letterSpacing: -0.44,
                                      fontWeight: FontWeight.w600,
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ),
                          Icon(Icons.keyboard_arrow_down),
                        ],
                      ),
                    ),
                  ),
            mHeight(20),
            isDentalSelectedAndSupported() == true || (nearestAppo && isProjectLoaded)
                ? InkWell(
                    onTap: () {
                      openDropdown(projectDropdownKey);
                    },
                    child: Container(
                        width: double.infinity,
                        decoration: containerRadius(Colors.white, 12),
                        margin: EdgeInsets.only(left: 20, right: 20),
                        padding: EdgeInsets.only(left: 10, right: 10, top: 12, bottom: 12),
                        child: Row(
                          children: [
                            Flexible(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Text(
                                    TranslationBase.of(context).selectHospital,
                                    style: TextStyle(
                                      fontSize: 11,
                                      letterSpacing: -0.44,
                                      fontWeight: FontWeight.w600,
                                    ),
                                  ),
                                  Container(
                                    height: 18,
                                    child: DropdownButtonHideUnderline(
                                      child: DropdownButton<HospitalsModel>(
                                        key: projectDropdownKey,
                                        hint: Text(TranslationBase.of(context).selectHospital),
                                        value: selectedHospital,
                                        iconSize: 0,
                                        isExpanded: true,
                                        style: TextStyle(fontSize: 14, letterSpacing: -0.56, color: Colors.black),
                                        items: projectsList.map((HospitalsModel item) {
                                          return DropdownMenuItem<HospitalsModel>(
                                            value: item,
                                            child: AutoSizeText(
                                              item.name!,
                                              maxLines: 1,
                                              minFontSize: 10,
                                              style: TextStyle(
                                                fontSize: SizeConfig.textMultiplier! * 1.6,
                                                fontWeight: FontWeight.w600,
                                                letterSpacing: -0.39,
                                                height: 0.8,
                                              ),
                                            ),
                                            // Text('${item.name!}'),
                                          );
                                        }).toList(),
                                        onChanged: (HospitalsModel? newValue) async {
                                          setState(() {
                                            HospitalsModel tempselectedHospital = new HospitalsModel.fromJson(newValue!.toJson());
                                            projectDropdownValue = newValue.mainProjectID.toString();
                                            if (dropdownValue!.split("-")[0] == "253") {
                                              Navigator.push(
                                                context,
                                                FadePage(
                                                  page: LaserClinic(selectedHospital: tempselectedHospital!),
                                                ),
                                              );
                                            } else {
                                              getDoctorsList(context);
                                            }
                                          });
                                        },
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                            ),
                            Icon(Icons.keyboard_arrow_down),
                          ],
                        )),
                  )
                : Container(),
          ],
        ),
      ),
    );
  }

  Widget inputWidget(String _labelText, String _hintText, TextEditingController _controller, {String? prefix, bool isEnable = true, bool hasSelection = false}) {
    return Container(
      padding: EdgeInsets.only(left: 16, right: 16, bottom: 15, top: 15),
      alignment: Alignment.center,
      decoration: BoxDecoration(
        borderRadius: BorderRadius.circular(15),
        color: Colors.white,
        border: Border.all(
          color: Color(0xffefefef),
          width: 1,
        ),
      ),
      child: InkWell(
        onTap: hasSelection ? () {} : null,
        child: Row(
          children: [
            Expanded(
              child: Column(
                mainAxisSize: MainAxisSize.min,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    _labelText,
                    style: TextStyle(
                      fontSize: 11,
                      fontWeight: FontWeight.w600,
                      color: Color(0xff2B353E),
                      letterSpacing: -0.44,
                    ),
                  ),
                  TextField(
                    enabled: isEnable,
                    scrollPadding: EdgeInsets.zero,
                    keyboardType: TextInputType.number,
                    controller: _controller,
                    onChanged: (value) => {},
                    style: TextStyle(
                      fontSize: 14,
                      height: 21 / 14,
                      fontWeight: FontWeight.w400,
                      color: Color(0xff2B353E),
                      letterSpacing: -0.44,
                    ),
                    decoration: InputDecoration(
                      isDense: true,
                      hintText: _hintText,
                      hintStyle: TextStyle(
                        fontSize: 14,
                        height: 21 / 14,
                        fontWeight: FontWeight.w400,
                        color: Color(0xff575757),
                        letterSpacing: -0.56,
                      ),
                      prefixIconConstraints: BoxConstraints(minWidth: 50),
                      prefixIcon: prefix == null
                          ? null
                          : Text(
                              "+" + prefix,
                              style: TextStyle(
                                fontSize: 14,
                                height: 21 / 14,
                                fontWeight: FontWeight.w500,
                                color: Color(0xff2E303A),
                                letterSpacing: -0.56,
                              ),
                            ),
                      contentPadding: EdgeInsets.zero,
                      border: InputBorder.none,
                      focusedBorder: InputBorder.none,
                      enabledBorder: InputBorder.none,
                    ),
                  ),
                ],
              ),
            ),
            if (hasSelection) Icon(Icons.keyboard_arrow_down_outlined),
          ],
        ),
      ),
    );
  }

//Changed By Aamir
  void openDropdown(GlobalKey key) {
    GestureDetector? detector;

    void searchForGestureDetector(BuildContext element) {
      element.visitChildElements((element) {
        if (element.widget != null && element.widget is GestureDetector) {
          detector = element.widget as GestureDetector?;
          //return false;
        } else {
          searchForGestureDetector(element);
        }

        //return true;
      });
    }

    searchForGestureDetector(key.currentContext!);
    assert(detector != null);

    detector!.onTap!();
  }

  // void openDropdown(GlobalKey key) {
  //   GestureDetector detector;
  //   void searchForGestureDetector(BuildContext element) {
  //     element.visitChildElements((element) {
  //       if (element.widget != null && element.widget is GestureDetector) {
  //         detector = element.widget;
  //         return false;
  //       } else {
  //         searchForGestureDetector(element);
  //       }
  //
  //       return true;
  //     });
  //   }
  //
  //   searchForGestureDetector(key.currentContext);
  //   assert(detector != null);
  //
  //   detector.onTap();
  // }

  bool isDentalSelectedAndSupported() {
    if (dropdownValue != null)
      return dropdownValue != "" && (dropdownValue!.split("-")[0] == "17" || dropdownValue!.split("-")[0] == "253") && isMobileAppDentalAllow;
    else
      return false;
  }

  getClinicsList() async {
    AppGlobal.context = context;
    if (await sharedPref.getObject(CLINICS_LIST) != null) {
      dynamic res = await sharedPref.getObject(CLINICS_LIST);
      setState(() {
        isMobileAppDentalAllow = res['ISMobileAppDentalAllow'];
        res['ListClinicCentralized'].forEach((v) {
          clinicsList.add(new ListClinicCentralized.fromJson(v));
        });
      });
      getProjectsList();
      // GifLoaderDialogUtils.hideDialog(context);
    } else {
      GifLoaderDialogUtils.showMyDialog(context);
      ClinicListService service = new ClinicListService();
      service.getClinicsList(context).then((res) {
        if (res['MessageStatus'] == 1) {
          setState(() {
            isMobileAppDentalAllow = res['ISMobileAppDentalAllow'];
            res['ListClinicCentralized'].forEach((v) {
              clinicsList.add(new ListClinicCentralized.fromJson(v));
            });
          });
          getProjectsList();
          GifLoaderDialogUtils.hideDialog(context);
        } else {}
      }).catchError((err) {
        print(err);
        GifLoaderDialogUtils.hideDialog(context);
      });
    }
  }

  getProjectsList() {
    int languageID = context.read<ProjectViewModel>().isArabic ? 1 : 2;
    ClinicListService service = new ClinicListService();
    List<HospitalsModel> projectsListLocal = [];
    service
        .getProjectsList(languageID, context)
        .then((res) {
          if (res['MessageStatus'] == 1) {
            setState(() {
              res['ListProject'].forEach((v) {
                projectsListLocal.add(new HospitalsModel.fromJson(v));
              });
              projectsList = projectsListLocal;
            });
            filterClinic();
            isProjectLoaded = true;
          } else {
            isProjectLoaded = false;
          }
          locationUtils.getCurrentLocation();
        })
        .catchError((err) {})
        .catchError((err) {
          print(err);
        });
  }

  // TODO Mosa_REMARk to come back later
  getDoctorsList(BuildContext context) {
    SearchInfo searchInfo = new SearchInfo();
    if (dropdownValue != null) if (dropdownValue!.split("-")[0] == "17") {
      searchInfo.ProjectID = int.parse(projectDropdownValue!);
      searchInfo.ClinicID = int.parse(dropdownValue!.split("-")[0]);
      searchInfo.hospital = selectedHospital;
      searchInfo.clinic = selectedClinic;
      searchInfo.date = DateTime.now();

      if (context.read<ProjectViewModel>().isLogin) {
        if (context.read<ProjectViewModel>().user.age! > 12) {
          navigateToDentalComplaints(context, searchInfo);
        } else {
          callDoctorsSearchAPI(17);
        }
      } else {
        navigateToDentalComplaints(context, searchInfo);
      }
    } else if (dropdownValue!.split("-")[0] == "253") {
      navigateToLaserClinic(context);
      // callDoctorsSearchAPI();
    } else if (dropdownValue!.split("-")[1] == "true"
        // && authProvider.isLogin &&
        // authUser.patientType == 1
        ) {
      Navigator.push(
        context,
        FadePage(
          page: LiveCareBookAppointment(clinicName: dropdownTitle, liveCareClinicID: dropdownValue!.split("-")[2], liveCareServiceID: dropdownValue!.split("-")[3]),
        ),
      ).then((value) {
        setState(() {
          if (value == "false") dropdownValue = "null";
        });
        if (value == "livecare") {
          Navigator.push(context, FadePage(page: LiveCareHome()));
        }
        if (value == "schedule") {
          callDoctorsSearchAPI(int.parse(dropdownValue!.split("-")[0]));
        }
      });
    } else {
      callDoctorsSearchAPI(int.parse(dropdownValue!.split("-")[0]));
    }
  }

  callDoctorsSearchAPI(int clinicID) {
    bool isArabic = context.read<ProjectViewModel>().isArabic;
    int languageID = context.read<ProjectViewModel>().isArabic ? 1 : 2;
    GifLoaderDialogUtils.showMyDialog(context);
    List<DoctorList> doctorsList = [];
    List<String> arr = [];
    List<String> arrDistance = [];
    List<String> result;
    int numAll;
    List<PatientDoctorAppointmentList> _patientDoctorAppointmentListHospital = [];

    DoctorsListService service = new DoctorsListService();
    service.getDoctorsList(clinicID, projectDropdownValue != "" ? int.parse(projectDropdownValue!) : 0, nearestAppo, languageID, context).then((res) async {
      GifLoaderDialogUtils.hideDialog(context);
      RegionList regionHospitalList = RegionList();

      if (res['MessageStatus'] == 1) {
        if (res['DoctorList'].length != 0) {
          res['DoctorList'].forEach((v) {
            doctorsList.add(new DoctorList.fromJson(
              v,
            ));
          });
          if (nearestAppo) {
            doctorsList.forEach((element) {
              List<PatientDoctorAppointmentList> doctorByHospital =
                  _patientDoctorAppointmentListHospital.where((elementClinic) => elementClinic.filterName == element.getProjectCompleteName()).toList();

              if (doctorByHospital.length != 0) {
                _patientDoctorAppointmentListHospital[_patientDoctorAppointmentListHospital.indexOf(doctorByHospital[0])].patientDoctorAppointmentList!.add(element);
              } else {
                _patientDoctorAppointmentListHospital.add(PatientDoctorAppointmentList(
                  filterName: element.getProjectCompleteName(),
                  distanceInKMs: element.projectDistanceInKiloMeters.toString(),
                  projectTopName: element.projectTopName,
                  projectBottomName: element.projectBottomName,
                  patientDoctorAppointment: element,
                  isHMC: element.isHMC,
                ));
              }
            });
            navigateToSearchResultsForNearestAppointment(context, doctorsList, _patientDoctorAppointmentListHospital);
            return;
          }

          regionHospitalList = await DoctorMapper.getMappedDoctor(doctorsList, isArabic: isArabic);
          var lat = await sharedPref.getDouble(USER_LAT);

          var lng = await sharedPref.getDouble(USER_LONG);
          var isLocationEnabled = (lat != null && lat != 0.0) && (lng != null && lng != 0.0);
          regionHospitalList = await DoctorMapper.sortList(isLocationEnabled, regionHospitalList);

          setState(() {});
        } else {
          GifLoaderDialogUtils.hideDialog(context);
          AppToast.showErrorToast(message: res['ErrorSearchMsg']);
        }

        GifLoaderDialogUtils.hideDialog(context);
        // navigateToSearchResults(context, doctorsList, _patientDoctorAppointmentListHospital);
        navigateToSearchResults(context, regionHospitalList);
      } else {
        GifLoaderDialogUtils.hideDialog(context);
        AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
      }
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      print(err);
      AppToast.showErrorToast(message: err, localContext: context);
    });
  }

  Future navigateToDentalComplaints(BuildContext context, SearchInfo searchInfo) async {
    Navigator.push(
      context,
      FadePage(
        page: DentalComplaints(searchInfo: searchInfo),
      ),
    ).then((value) {
      setState(() {
        dropdownValue = "null";
      });
    });
  }

  navigateToSearchResultsForNearestAppointment(context, List<DoctorList> docList, List<PatientDoctorAppointmentList> patientDoctorAppointmentListHospital) {
    Navigator.push(
        context,
        FadePage(
            page: SearchResults(
          isLiveCareAppointment: false,
          isDoctorNameSearch: true,
          doctorsList: docList,
          patientDoctorAppointmentListHospital: patientDoctorAppointmentListHospital,
          isDoctorSearchResult: true,
        )));
  }

  Future navigateToLaserClinic(BuildContext context) async {
    Navigator.push(
      context,
      FadePage(
        page: LaserBooking(),
      ),
    ).then((value) {
      setState(() {
        dropdownValue = "null";
      });
    });
  }

  navigateToSearchResults(context, RegionList regionHospitalList) {
    // Navigator.push(context,
    //     FadePage(page: SearchResults(isLiveCareAppointment: false, isDoctorNameSearch: true, doctorsList: docList, patientDoctorAppointmentListHospital: patientDoctorAppointmentListHospital, isDoctorSearchResult: true,)));
    Navigator.push(
        context,
        FadePage(
            page: SearchResultWithTab(
          doctorsList: [],
          patientDoctorAppointmentListHospital: regionHospitalList,
          isLiveCareAppointment: false,
          isDoctorSearchResult: true,
        )));
  }

  filterClinic() {
    setState(() {
      if (widget.clnicIds != null && widget.clnicIds!.length > 0) {
        clinicsList = clinicsList.where((i) => widget.clnicIds!.indexOf(i.clinicID) > -1).toList();
        isLoaded = true;
      }
    });
  }
}
