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/OBGyneProcedureListResponse.dart';
import 'package:hmg_patient_app/pages/BookAppointment/widgets/DoctorView.dart';
import 'package:hmg_patient_app/theme/colors.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/others/app_expandable_notifier.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class SearchResults extends StatelessWidget {
  List<DoctorList> doctorsList = [];
  List<PatientDoctorAppointmentList> patientDoctorAppointmentListHospital;
  bool isLiveCareAppointment;
  bool isObGyneAppointment;
  bool isDoctorNameSearch;
  OBGyneProcedureListResponse? obGyneProcedureListResponse;
  bool isDoctorSearchResult;

  SearchResults(
      {required this.doctorsList,
      required this.patientDoctorAppointmentListHospital,
      this.isObGyneAppointment = false,
      this.isDoctorNameSearch = false,
      required this.isLiveCareAppointment,
      required this.isDoctorSearchResult,
      this.obGyneProcedureListResponse});

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      appBarTitle: TranslationBase.of(context).bookAppo,
      isShowDecPage: false,
      isShowAppBar: true,
      showNewAppBarTitle: true,
      showNewAppBar: true,
      backgroundColor: CustomColors.appBackgroudGrey2Color,
      body: patientDoctorAppointmentListHospital.isNotEmpty
          ? ListView.separated(
              addAutomaticKeepAlives: true,
              physics: BouncingScrollPhysics(),
              separatorBuilder: (context, index) {
                return Container(
                  height: 12,
                  margin: EdgeInsets.only(left: 21, right: 21),
                );
              },
              itemBuilder: (context, index) {
                return AppExpandableNotifier(
                  title: (patientDoctorAppointmentListHospital[index].distanceInKMs != "0")
                      ? patientDoctorAppointmentListHospital[index].filterName! + " - " + patientDoctorAppointmentListHospital[index].distanceInKMs! + " " + TranslationBase.of(context).km
                      : patientDoctorAppointmentListHospital[index].filterName,
                  projectTitleTop: patientDoctorAppointmentListHospital[index].projectTopName,
                  projectTitleBottom: (patientDoctorAppointmentListHospital[index].distanceInKMs != "0")
                      ? patientDoctorAppointmentListHospital[index].projectBottomName.toString() +
                          " - " +
                          patientDoctorAppointmentListHospital[index].distanceInKMs! +
                          " " +
                          TranslationBase.of(context).km
                      : patientDoctorAppointmentListHospital[index].projectBottomName.toString(),
                  isTitleSingleLine: false,
                  isHMC: patientDoctorAppointmentListHospital[index].isHMC ??
                      false,
                  isForAppointmentSearch: true,
                  isDoctorSearchResult: isDoctorSearchResult,
                  isExpand: patientDoctorAppointmentListHospital.length == 1 ? true : false,
                  bodyWidget: ListView.separated(
                      shrinkWrap: true,
                      physics: NeverScrollableScrollPhysics(),
                      padding: EdgeInsets.only(bottom: 10, top: 10, left: 21, right: 21),
                      itemBuilder: (context, _index) {
                        final doctor = patientDoctorAppointmentListHospital[index].patientDoctorAppointmentList![_index];
                        return DoctorView(
                            doctor: doctor,
                            isLiveCareAppointment: isLiveCareAppointment,
                            isObGyneAppointment: isObGyneAppointment,
                            isDoctorNameSearch: isDoctorNameSearch,
                            obGyneProcedureListResponse: obGyneProcedureListResponse,
                            isShowDate: false,
                            onTap: () {
                              context.read<ProjectViewModel>().analytics.appointment.book_appointment_select_doctor(appointment_type: 'regular', doctor: doctor);
                            });
                      },
                      separatorBuilder: (context, index) => SizedBox(height: 14),
                      itemCount: patientDoctorAppointmentListHospital[index].patientDoctorAppointmentList!.length),
                );
              },
              itemCount: patientDoctorAppointmentListHospital.length,
            )
          : getNoDataWidget(context),
    );
  }
}
