import 'dart:async';

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_staggered_animations/flutter_staggered_animations.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/app_export.dart';
import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/core/utils/date_util.dart';
import 'package:hmg_patient_app_new/core/utils/request_utils.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/book_appointments/book_appointments_view_model.dart';
import 'package:hmg_patient_app_new/features/book_appointments/models/resp_models/doctors_list_response_model.dart';
import 'package:hmg_patient_app_new/features/insurance/insurance_view_model.dart';
import 'package:hmg_patient_app_new/features/medical_file/medical_file_view_model.dart';
import 'package:hmg_patient_app_new/features/medical_file/models/family_file_response_model.dart';
import 'package:hmg_patient_app_new/features/medical_file/models/patient_sickleave_response_model.dart';
import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/patient_appointment_history_response_model.dart';
import 'package:hmg_patient_app_new/features/my_appointments/my_appointments_view_model.dart';
import 'package:hmg_patient_app_new/features/prescriptions/prescriptions_view_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.dart';
import 'package:hmg_patient_app_new/presentation/appointments/my_appointments_page.dart';
import 'package:hmg_patient_app_new/presentation/appointments/my_doctors_page.dart';
import 'package:hmg_patient_app_new/presentation/book_appointment/book_appointment_page.dart';
import 'package:hmg_patient_app_new/presentation/book_appointment/widgets/appointment_calendar.dart';
import 'package:hmg_patient_app_new/presentation/insurance/insurance_home_page.dart';
import 'package:hmg_patient_app_new/presentation/insurance/widgets/patient_insurance_card.dart';
import 'package:hmg_patient_app_new/presentation/lab/collapsing_list_view.dart';
import 'package:hmg_patient_app_new/presentation/medical_file/medical_reports_page.dart';
import 'package:hmg_patient_app_new/presentation/medical_file/patient_sickleaves_list_page.dart';
import 'package:hmg_patient_app_new/presentation/medical_file/vaccine_list_page.dart';
import 'package:hmg_patient_app_new/presentation/medical_file/widgets/lab_rad_card.dart';
import 'package:hmg_patient_app_new/presentation/medical_file/widgets/medical_file_card.dart';
import 'package:hmg_patient_app_new/presentation/medical_file/widgets/patient_sick_leave_card.dart';
import 'package:hmg_patient_app_new/presentation/my_family/my_Family.dart';
import 'package:hmg_patient_app_new/presentation/my_family/widget/my_family_sheet.dart';
import 'package:hmg_patient_app_new/presentation/prescriptions/prescriptions_list_page.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/chip/app_custom_chip_widget.dart';
import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
import 'package:hmg_patient_app_new/widgets/custom_tab_bar.dart';
import 'package:hmg_patient_app_new/widgets/input_widget.dart';
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';
import 'package:hmg_patient_app_new/widgets/routes/custom_page_route.dart';
import 'package:hmg_patient_app_new/widgets/shimmer/movies_shimmer_widget.dart';
import 'package:hmg_patient_app_new/widgets/transitions/fade_page.dart';
import 'package:provider/provider.dart';

import '../prescriptions/prescription_detail_page.dart';
import 'widgets/medical_file_appointment_card.dart';

class MedicalFilePage extends StatefulWidget {
  MedicalFilePage({super.key});

  @override
  State<MedicalFilePage> createState() => _MedicalFilePageState();
}

class _MedicalFilePageState extends State<MedicalFilePage> {
  late InsuranceViewModel insuranceViewModel;
  late AppState appState;
  late MyAppointmentsViewModel myAppointmentsViewModel;
  late MedicalFileViewModel medicalFileViewModel;
  late BookAppointmentsViewModel bookAppointmentsViewModel;

  int currentIndex = 0;

  @override
  void initState() {
    scheduleMicrotask(() {
      if (appState.isAuthenticated) {
        insuranceViewModel.initInsuranceProvider();
        medicalFileViewModel.setIsPatientSickLeaveListLoading(true);
        medicalFileViewModel.getPatientSickLeaveList();
        medicalFileViewModel.getFamilyFiles();
        medicalFileViewModel.onTabChanged(0);
      }
    });
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    insuranceViewModel = Provider.of<InsuranceViewModel>(context, listen: false);
    myAppointmentsViewModel = Provider.of<MyAppointmentsViewModel>(context, listen: false);
    medicalFileViewModel = Provider.of<MedicalFileViewModel>(context, listen: false);
    bookAppointmentsViewModel = Provider.of<BookAppointmentsViewModel>(context, listen: false);
    appState = getIt.get<AppState>();
    NavigationService navigationService = getIt.get<NavigationService>();
    return Scaffold(
      backgroundColor: AppColors.bgScaffoldColor,
      body: CollapsingListView(
        title: LocaleKeys.medicalFile.tr(context: context),
        isLeading: false,
        child: SingleChildScrollView(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              SizedBox(height: 16.h),
              TextInputWidget(
                labelText: LocaleKeys.search.tr(context: context),
                hintText: "Type any record",
                controller: TextEditingController(),
                keyboardType: TextInputType.number,
                isEnable: true,
                prefix: null,
                autoFocus: false,
                isBorderAllowed: false,
                isAllowLeadingIcon: true,
                padding: EdgeInsets.symmetric(vertical: 8.h, horizontal: 8.h),
                leadingIcon: AppAssets.student_card,
              ).paddingSymmetrical(24.h, 0.0),
              SizedBox(height: 16.h),
              Container(
                width: double.infinity,
                decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24),
                child: Padding(
                  padding: EdgeInsets.all(16.h),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Row(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Image.asset(appState.getAuthenticatedUser()?.gender == 1 ? AppAssets.male_img : AppAssets.femaleImg, width: 56.h, height: 56.h),
                          SizedBox(width: 8.h),
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              "${appState.getAuthenticatedUser()!.firstName} ${appState.getAuthenticatedUser()!.lastName}".toText18(isBold: true),
                              SizedBox(height: 4.h),
                              Wrap(
                                direction: Axis.horizontal,
                                spacing: 4.h,
                                runSpacing: 4.h,
                                children: [
                                  AppCustomChipWidget(
                                    icon: AppAssets.file_icon,
                                    labelText: "${LocaleKeys.fileNo.tr(context: context)}: ${appState.getAuthenticatedUser()!.patientId}",
                                  ),
                                  AppCustomChipWidget(
                                    icon: AppAssets.checkmark_icon,
                                    labelText: LocaleKeys.verified.tr(context: context),
                                    iconColor: AppColors.successColor,
                                  ),
                                ],
                              ),
                            ],
                          )
                        ],
                      ),
                      SizedBox(height: 16.h),
                      Divider(color: AppColors.dividerColor, height: 1.h),
                      SizedBox(height: 16.h),
                      Wrap(
                        direction: Axis.horizontal,
                        spacing: 4.h,
                        runSpacing: 4.h,
                        children: [
                          AppCustomChipWidget(
                            labelText: "${appState.getAuthenticatedUser()!.age} Years Old",
                          ),
                          AppCustomChipWidget(
                            icon: AppAssets.blood_icon,
                            labelText: "${LocaleKeys.bloodType.tr(context: context)}: ${appState.getUserBloodGroup}",
                            iconColor: AppColors.primaryRedColor,
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
              ).paddingSymmetrical(24.h, 0.0),
              SizedBox(height: 16.h),
              Consumer<MedicalFileViewModel>(builder: (context, medicalFileVM, child) {
                return Column(
                  children: [
                    CustomTabBar(
                      activeTextColor: Color(0xffED1C2B),
                      activeBackgroundColor: Color(0xffED1C2B).withValues(alpha: .1),
                      tabs: [
                        CustomTabBarModel(AppAssets.myFilesBottom, LocaleKeys.general.tr(context: context).needTranslation),
                        CustomTabBarModel(AppAssets.insurance, LocaleKeys.insurance.tr(context: context)),
                        CustomTabBarModel(AppAssets.requests, LocaleKeys.request.tr(context: context).needTranslation),
                        CustomTabBarModel(AppAssets.more, "More".needTranslation),
                      ],
                      onTabChange: (index) {
                        print(index);
                        medicalFileVM.onTabChanged(index);
                      },
                    ).paddingSymmetrical(24.h, 0.0),
                    SizedBox(height: 24.h),
                    getSelectedTabData(medicalFileVM.selectedTabIndex),
                  ],
                );
              }),
            ],
          ),
        ),
      ),
    );
  }

  openDoctorScheduleCalendar(PatientAppointmentHistoryResponseModel patientAppointmentHistoryResponseModel) async {
    DoctorsListResponseModel doctor = DoctorsListResponseModel(
      clinicID: patientAppointmentHistoryResponseModel.clinicID,
      projectID: patientAppointmentHistoryResponseModel.projectID,
      doctorID: patientAppointmentHistoryResponseModel.doctorID,
      doctorImageURL: patientAppointmentHistoryResponseModel.doctorImageURL,
      doctorTitle: patientAppointmentHistoryResponseModel.doctorTitle,
      name: patientAppointmentHistoryResponseModel.doctorNameObj,
      nationalityFlagURL: "https://hmgwebservices.com/Images/flag/SYR.png",
      speciality: [],
      clinicName: patientAppointmentHistoryResponseModel.clinicName,
      projectName: patientAppointmentHistoryResponseModel.projectName,
    );
    bookAppointmentsViewModel.setSelectedDoctor(doctor);
    LoaderBottomSheet.showLoader();
    await bookAppointmentsViewModel.getDoctorFreeSlots(
        isBookingForLiveCare: false,
        onSuccess: (dynamic respData) async {
          LoaderBottomSheet.hideLoader();
          showCommonBottomSheetWithoutHeight(
            title: "Pick a Date".needTranslation,
            context,
            child: AppointmentCalendar(),
            isFullScreen: false,
            isCloseButtonVisible: true,
            callBackFunc: () {},
          );
        },
        onError: (err) {
          LoaderBottomSheet.hideLoader();
          showCommonBottomSheetWithoutHeight(
            context,
            child: Utils.getErrorWidget(loadingText: err),
            callBackFunc: () {},
            isFullScreen: false,
            isCloseButtonVisible: true,
          );
        });
  }

  Widget getSelectedTabData(int index) {
    switch (index) {
      case 0:
        //General Tab Data
        return Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                "Appointments & visits".needTranslation.toText18(isBold: true),
                Row(
                  children: [
                    LocaleKeys.viewAll.tr().toText12(color: AppColors.primaryRedColor, fontWeight: FontWeight.w500),
                    SizedBox(width: 2.h),
                    Icon(Icons.arrow_forward_ios, color: AppColors.primaryRedColor, size: 10.h),
                  ],
                ),
              ],
            ).paddingSymmetrical(24.h, 0.h).onPress(() {
              Navigator.of(context).push(
                CustomPageRoute(
                  page: MyAppointmentsPage(),
                ),
              );
            }),
            Consumer<MyAppointmentsViewModel>(builder: (context, myAppointmentsVM, child) {
              return SizedBox(
                height: 200.h,
                child: ListView.separated(
                  scrollDirection: Axis.horizontal,
                  padding: EdgeInsets.only(top: 16.h, left: 24.h, right: 24.h, bottom: 0.h),
                  shrinkWrap: true,
                  itemCount: myAppointmentsVM.isMyAppointmentsLoading ? 5 : (myAppointmentsVM.patientAppointmentsHistoryList.isNotEmpty ? myAppointmentsVM.patientAppointmentsHistoryList.length : 1),
                  itemBuilder: (context, index) {
                    return AnimationConfiguration.staggeredList(
                      position: index,
                      duration: const Duration(milliseconds: 500),
                      child: SlideAnimation(
                        horizontalOffset: 100.0,
                        child: FadeInAnimation(
                          child: AnimatedContainer(
                            duration: Duration(milliseconds: 300),
                            curve: Curves.easeInOut,
                            child: myAppointmentsVM.isMyAppointmentsLoading
                                ? MedicalFileAppointmentCard(
                                    patientAppointmentHistoryResponseModel: PatientAppointmentHistoryResponseModel(),
                                    myAppointmentsViewModel: myAppointmentsVM,
                                    onRescheduleTap: () {},
                                    onAskDoctorTap: () {},
                                  )
                                : myAppointmentsVM.patientAppointmentsHistoryList.isNotEmpty
                                    ? MedicalFileAppointmentCard(
                                        patientAppointmentHistoryResponseModel: myAppointmentsVM.patientAppointmentsHistoryList[index],
                                        myAppointmentsViewModel: myAppointmentsViewModel,
                                        onRescheduleTap: () {
                                          openDoctorScheduleCalendar(myAppointmentsVM.patientAppointmentsHistoryList[index]);
                                        },
                                        onAskDoctorTap: () {},
                                      )
                                    : Container(
                                        width: MediaQuery.of(context).size.width - 48.h,
                                        decoration: RoundedRectangleBorder().toSmoothCornerDecoration(color: AppColors.whiteColor, borderRadius: 24, hasShadow: true),
                                        child: Padding(
                                          padding: EdgeInsets.all(12.h),
                                          child: Column(
                                            children: [
                                              Utils.buildSvgWithAssets(icon: AppAssets.home_calendar_icon, width: 32.h, height: 32.h),
                                              SizedBox(height: 12.h),
                                              "You do not have any appointments. Please book an appointment".needTranslation.toText12(isCenter: true),
                                              SizedBox(height: 12.h),
                                              CustomButton(
                                                text: LocaleKeys.bookAppo.tr(context: context),
                                                onPressed: () {
                                                  Navigator.of(context).push(
                                                    CustomPageRoute(
                                                      page: BookAppointmentPage(),
                                                    ),
                                                  );
                                                },
                                                backgroundColor: Color(0xffFEE9EA),
                                                borderColor: Color(0xffFEE9EA),
                                                textColor: Color(0xffED1C2B),
                                                fontSize: 14,
                                                fontWeight: FontWeight.w500,
                                                borderRadius: 12,
                                                padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
                                                height: 40,
                                                icon: AppAssets.add_icon,
                                                iconColor: AppColors.primaryRedColor,
                                              ),
                                            ],
                                          ),
                                        ),
                                      ),
                          ),
                        ),
                      ),
                    );
                  },
                  separatorBuilder: (BuildContext cxt, int index) => SizedBox(width: 12.h),
                ),
              );
            }),
            SizedBox(height: 24.h),
            "Lab & Radiology".needTranslation.toText18(isBold: true).paddingSymmetrical(24.h, 0.h),
            SizedBox(height: 16.h),
            Row(
              children: [
                Expanded(
                  child: LabRadCard(
                    icon: AppAssets.lab_result_icon,
                    labelText: LocaleKeys.labResults.tr(context: context),
                    labOrderTests: ["Complete blood count", "Creatinine", "Blood Sugar"],
                  ),
                ),
                SizedBox(width: 16.h),
                Expanded(
                  child: LabRadCard(
                    icon: AppAssets.radiology_icon,
                    labelText: LocaleKeys.radiology.tr(context: context),
                    labOrderTests: ["Chest X-ray", "Abdominal Ultrasound", "Dental X-ray"],
                  ),
                ),
              ],
            ).paddingSymmetrical(24.h, 0.h),
            SizedBox(height: 24.h),
            "Active Medications & Prescriptions".needTranslation.toText18(isBold: true).paddingSymmetrical(24.h, 0.h),
            SizedBox(height: 16.h),
            Consumer<PrescriptionsViewModel>(builder: (context, prescriptionVM, child) {
              return prescriptionVM.isPrescriptionsOrdersLoading
                  ? const MoviesShimmerWidget().paddingSymmetrical(24.h, 0.h)
                  : prescriptionVM.patientPrescriptionOrders.isNotEmpty
                      ? Container(
                          decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
                            color: Colors.white,
                            borderRadius: 20.h,
                          ),
                          child: Padding(
                            padding: EdgeInsets.all(16.h),
                            child: Column(
                              children: [
                                ListView.separated(
                                  itemCount: prescriptionVM.patientPrescriptionOrders.length,
                                  shrinkWrap: true,
                                  padding: const EdgeInsets.only(left: 0, right: 8),
                                  physics: NeverScrollableScrollPhysics(),
                                  itemBuilder: (context, index) {
                                    return AnimationConfiguration.staggeredList(
                                      position: index,
                                      duration: const Duration(milliseconds: 500),
                                      child: SlideAnimation(
                                        verticalOffset: 100.0,
                                        child: FadeInAnimation(
                                          child: Row(
                                            children: [
                                              Image.network(
                                                prescriptionVM.patientPrescriptionOrders[index].doctorImageURL!,
                                                width: 40.h,
                                                height: 40.h,
                                                fit: BoxFit.fill,
                                              ).circle(100),
                                              SizedBox(width: 16.h),
                                              Expanded(
                                                child: Column(
                                                  crossAxisAlignment: CrossAxisAlignment.start,
                                                  children: [
                                                    prescriptionVM.patientPrescriptionOrders[index].doctorName!.toText16(isBold: true),
                                                    SizedBox(height: 4.h),
                                                    Wrap(
                                                      direction: Axis.horizontal,
                                                      spacing: 3.h,
                                                      runSpacing: 4.h,
                                                      children: [
                                                        AppCustomChipWidget(labelText: prescriptionVM.patientPrescriptionOrders[index].clinicDescription!),
                                                        AppCustomChipWidget(
                                                          icon: AppAssets.doctor_calendar_icon,
                                                          labelText: DateUtil.formatDateToDate(DateUtil.convertStringToDate(prescriptionVM.patientPrescriptionOrders[index].appointmentDate), false),
                                                        ),
                                                      ],
                                                    ),
                                                  ],
                                                ),
                                              ),
                                              // SizedBox(width: 40.h),
                                              Transform.flip(
                                                  flipX: appState.isArabic() ? true : false,
                                                  child: Utils.buildSvgWithAssets(icon: AppAssets.forward_arrow_icon, width: 15.h, height: 15.h, fit: BoxFit.contain, iconColor: AppColors.textColor)),
                                            ],
                                          ).onPress(() {
                                            prescriptionVM.setPrescriptionsDetailsLoading();
                                            Navigator.of(context).push(
                                              CustomPageRoute(
                                                page: PrescriptionDetailPage(prescriptionsResponseModel: prescriptionVM.patientPrescriptionOrders[index]),
                                              ),
                                            );
                                          }),
                                        ),
                                      ),
                                    );
                                  },
                                  separatorBuilder: (BuildContext cxt, int index) => SizedBox(height: 16.h),
                                ),
                                SizedBox(height: 16.h),
                                const Divider(color: AppColors.dividerColor),
                                SizedBox(height: 16.h),
                                Row(
                                  children: [
                                    Expanded(
                                      child: CustomButton(
                                        text: "All Prescriptions".needTranslation,
                                        onPressed: () {
                                          Navigator.of(context).push(
                                            CustomPageRoute(
                                              page: PrescriptionsListPage(),
                                            ),
                                          );
                                        },
                                        backgroundColor: AppColors.secondaryLightRedColor,
                                        borderColor: AppColors.secondaryLightRedColor,
                                        textColor: AppColors.primaryRedColor,
                                        fontSize: 14,
                                        fontWeight: FontWeight.w500,
                                        borderRadius: 12.h,
                                        height: 40.h,
                                        icon: AppAssets.requests,
                                        iconColor: AppColors.primaryRedColor,
                                        iconSize: 16.h,
                                      ),
                                    ),
                                    SizedBox(width: 10.h),
                                    Expanded(
                                      child: CustomButton(
                                        text: "All Medications".needTranslation,
                                        onPressed: () {},
                                        backgroundColor: AppColors.secondaryLightRedColor,
                                        borderColor: AppColors.secondaryLightRedColor,
                                        textColor: AppColors.primaryRedColor,
                                        fontSize: 14,
                                        fontWeight: FontWeight.w500,
                                        borderRadius: 12.h,
                                        height: 40.h,
                                        icon: AppAssets.all_medications_icon,
                                        iconColor: AppColors.primaryRedColor,
                                        iconSize: 16.h,
                                      ),
                                    ),
                                  ],
                                ),
                              ],
                            ),
                          ),
                        ).paddingSymmetrical(24.h, 0.h)
                      : SizedBox.shrink();
            }),
            SizedBox(height: 24.h),
            //My Doctor Section
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                LocaleKeys.myDoctor.tr(context: context).toText18(isBold: true),
                Row(
                  children: [
                    LocaleKeys.viewAll.tr().toText12(color: AppColors.primaryRedColor, fontWeight: FontWeight.w500),
                    SizedBox(width: 2.h),
                    Icon(Icons.arrow_forward_ios, color: AppColors.primaryRedColor, size: 10.h),
                  ],
                ).onPress(() {
                  myAppointmentsViewModel.setIsPatientMyDoctorsLoading(true);
                  myAppointmentsViewModel.getPatientMyDoctors();
                  Navigator.of(context).push(
                    CustomPageRoute(
                      page: MyDoctorsPage(),
                    ),
                  );
                }),
              ],
            ).paddingSymmetrical(24.h, 0.h),
            SizedBox(height: 16.h),
            Consumer<MyAppointmentsViewModel>(builder: (context, myAppointmentsVM, child) {
              return SizedBox(
                height: 120.h,
                child: ListView.separated(
                  scrollDirection: Axis.horizontal,
                  itemCount: myAppointmentsVM.isPatientMyDoctorsLoading ? 5 : myAppointmentsVM.patientMyDoctorsList.length,
                  shrinkWrap: true,
                  padding: EdgeInsets.only(left: 24.h, right: 24.h),
                  itemBuilder: (context, index) {
                    return myAppointmentsVM.isPatientMyDoctorsLoading
                        ? SizedBox(
                            width: 80.h,
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.center,
                              children: [
                                Image.network(
                                  "https://hmgwebservices.com/Images/MobileImages/DUBAI/unkown_female.png",
                                  width: 64.h,
                                  height: 64.h,
                                  fit: BoxFit.fill,
                                ).circle(100).toShimmer2(isShow: true, radius: 50.h),
                                SizedBox(height: 8.h),
                                Expanded(
                                  child: ("Dr. John Smith Smith Smith").toString().toText12(fontWeight: FontWeight.w500, isCenter: true, maxLine: 2).toShimmer2(isShow: true),
                                ),
                              ],
                            ),
                          )
                        : AnimationConfiguration.staggeredList(
                            position: index,
                            duration: const Duration(milliseconds: 1000),
                            child: SlideAnimation(
                              horizontalOffset: 100.0,
                              child: FadeInAnimation(
                                child: SizedBox(
                                  width: 80.h,
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.center,
                                    children: [
                                      Image.network(
                                        myAppointmentsVM.patientMyDoctorsList[index].doctorImageURL!,
                                        width: 64.h,
                                        height: 64.h,
                                        fit: BoxFit.fill,
                                      ).circle(100).toShimmer2(isShow: false, radius: 50.h),
                                      SizedBox(height: 8.h),
                                      Expanded(
                                        child: (myAppointmentsVM.patientMyDoctorsList[index].doctorName)
                                            .toString()
                                            .toText12(fontWeight: FontWeight.w500, isCenter: true, maxLine: 2)
                                            .toShimmer2(isShow: false),
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                            ),
                          );
                  },
                  separatorBuilder: (BuildContext cxt, int index) => SizedBox(width: 8.h),
                ),
              );
            }),
            SizedBox(height: 24.h),
            "Others".needTranslation.toText18(isBold: true).paddingSymmetrical(24.h, 0.h),
            SizedBox(height: 16.h),
            GridView(
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, crossAxisSpacing: 13, mainAxisSpacing: 13),
              physics: NeverScrollableScrollPhysics(),
              padding: EdgeInsets.zero,
              shrinkWrap: true,
              children: [
                MedicalFileCard(
                  label: "Eye Test Results".needTranslation,
                  textColor: AppColors.blackColor,
                  backgroundColor: AppColors.whiteColor,
                  svgIcon: AppAssets.eye_result_icon,
                  isLargeText: true,
                  iconSize: 40.h,
                ),
                MedicalFileCard(
                  label: "Allergy Info".needTranslation,
                  textColor: AppColors.blackColor,
                  backgroundColor: AppColors.whiteColor,
                  svgIcon: AppAssets.allergy_info_icon,
                  isLargeText: true,
                  iconSize: 40.h,
                ),
                MedicalFileCard(
                  label: "Vaccine Info".needTranslation,
                  textColor: AppColors.blackColor,
                  backgroundColor: AppColors.whiteColor,
                  svgIcon: AppAssets.vaccine_info_icon,
                  isLargeText: true,
                  iconSize: 40.h,
                ).onPress(() {
                  Navigator.of(context).push(
                    CustomPageRoute(
                      page: VaccineListPage(),
                    ),
                  );
                }),
              ],
            ).paddingSymmetrical(24.h, 0.0),
            SizedBox(height: 24.h),
          ],
        );
      case 1:
        //Insurance Tab Data
        return Column(
          children: [
            Consumer<InsuranceViewModel>(builder: (context, insuranceVM, child) {
              return insuranceVM.isInsuranceLoading
                  ? const MoviesShimmerWidget().paddingSymmetrical(24.h, 0.0)
                  : insuranceVM.patientInsuranceList.isNotEmpty
                      ? PatientInsuranceCard(
                          insuranceCardDetailsModel: insuranceVM.patientInsuranceList.first,
                          isInsuranceExpired: DateTime.now().isAfter(
                            DateUtil.convertStringToDate(insuranceVM.patientInsuranceList.first.cardValidTo),
                          ),
                        )
                      : SizedBox.shrink();
            }),
            SizedBox(height: 10.h),
            GridView(
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, crossAxisSpacing: 13, mainAxisSpacing: 13),
              physics: NeverScrollableScrollPhysics(),
              padding: EdgeInsets.only(top: 12),
              shrinkWrap: true,
              children: [
                MedicalFileCard(
                        label: "Update Insurance".needTranslation,
                        textColor: AppColors.blackColor,
                        backgroundColor: AppColors.whiteColor,
                        svgIcon: AppAssets.eye_result_icon,
                        isLargeText: false,
                        iconSize: 36.h)
                    .onPress(() {
                  Navigator.of(context).push(
                    CustomPageRoute(
                      page: InsuranceHomePage(),
                    ),
                  );
                }),
                MedicalFileCard(
                    label: "Insurance Approvals".needTranslation,
                    textColor: AppColors.blackColor,
                    backgroundColor: AppColors.whiteColor,
                    svgIcon: AppAssets.eye_result_icon,
                    isLargeText: false,
                    iconSize: 36.h),
                MedicalFileCard(
                    label: "My Invoices           List".needTranslation,
                    textColor: AppColors.blackColor,
                    backgroundColor: AppColors.whiteColor,
                    svgIcon: AppAssets.eye_result_icon,
                    isLargeText: false,
                    iconSize: 36.h),
                MedicalFileCard(
                    label: "Ancillary Orders List".needTranslation,
                    textColor: AppColors.blackColor,
                    backgroundColor: AppColors.whiteColor,
                    svgIcon: AppAssets.eye_result_icon,
                    isLargeText: false,
                    iconSize: 36.h),
              ],
            ).paddingSymmetrical(24.h, 0.0),
            SizedBox(height: 16.h),
          ],
        );
      case 2:
        // Requests Tab Data
        return Column(
          children: [
            Consumer<MedicalFileViewModel>(builder: (context, medicalFileVM, child) {
              return medicalFileVM.isPatientSickLeaveListLoading
                  ? PatientSickLeaveCard(
                      patientSickLeavesResponseModel: PatientSickLeavesResponseModel(),
                      isLoading: true,
                    ).paddingSymmetrical(24.h, 0.0)
                  : medicalFileVM.patientSickLeaveList.isNotEmpty
                      ? PatientSickLeaveCard(
                          patientSickLeavesResponseModel: medicalFileVM.patientSickLeaveList.first,
                          isLoading: false,
                        ).paddingSymmetrical(24.h, 0.0)
                      : SizedBox.shrink();
            }),
            SizedBox(height: 16.h),
            GridView(
              gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, crossAxisSpacing: 13, mainAxisSpacing: 13),
              physics: NeverScrollableScrollPhysics(),
              padding: EdgeInsets.zero,
              shrinkWrap: true,
              children: [
                MedicalFileCard(
                  label: LocaleKeys.monthlyReports.tr(context: context),
                  textColor: AppColors.blackColor,
                  backgroundColor: AppColors.whiteColor,
                  svgIcon: AppAssets.eye_result_icon,
                  isLargeText: false,
                  iconSize: 40.h,
                ),
                MedicalFileCard(
                  label: "Medical Reports".needTranslation,
                  textColor: AppColors.blackColor,
                  backgroundColor: AppColors.whiteColor,
                  svgIcon: AppAssets.allergy_info_icon,
                  isLargeText: false,
                  iconSize: 40.h,
                ).onPress(() {
                  medicalFileViewModel.setIsPatientMedicalReportsLoading(true);
                  medicalFileViewModel.getPatientMedicalReportList();
                  Navigator.of(context).push(
                    CustomPageRoute(
                      page: MedicalReportsPage(),
                    ),
                  );
                }),
                MedicalFileCard(
                  label: "Sick Leave Report".needTranslation,
                  textColor: AppColors.blackColor,
                  backgroundColor: AppColors.whiteColor,
                  svgIcon: AppAssets.vaccine_info_icon,
                  isLargeText: false,
                  iconSize: 40.h,
                ).onPress(() {
                  Navigator.of(context).push(
                    CustomPageRoute(
                      page: PatientSickleavesListPage(),
                    ),
                  );
                }),
              ],
            ).paddingSymmetrical(24.h, 0.0),
            SizedBox(height: 24.h),
          ],
        );
      case 3:
        return Container();
      default:
        return Container();
    }
  }

  getMember() {
    // AuthanticationViewModel authanticationViewModel = getIt.get<AuthanticationViewModel>();
    // RequestUtils.getAddFamilyRequest(nationalIDorFile: nationalIDorFile, mobileNo: mobileNo, countryCode: countryCode, loginType: loginType);
  }
}
