import 'package:hmg_patient_app/core/enum/filter_type.dart';
import 'package:hmg_patient_app/core/model/prescriptions/Prescriptions.dart';
import 'package:hmg_patient_app/core/viewModels/medical/prescriptions_view_model.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/pages/medical/prescriptions/prescription_items_page.dart';
import 'package:hmg_patient_app/uitl/date_uitl.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/widgets/data_display/medical/doctor_card.dart';
import 'package:hmg_patient_app/widgets/new_design/my_tab_view.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:hmg_patient_app/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PrescriptionsPage extends StatelessWidget {
  final VoidCallback? showOrderLog;
  final FilterType filterType;
  final PrescriptionsViewModel? prescriptionsViewModel;

  const PrescriptionsPage(this.filterType, {Key? key, this.prescriptionsViewModel, this.showOrderLog}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
        baseViewModel: prescriptionsViewModel,
        body: ListView.separated(
          addAutomaticKeepAlives: true,
          physics: BouncingScrollPhysics(),
          padding: EdgeInsets.only(top: 12),
          separatorBuilder: (context, index) {
            return Container(
              height: 12,
              margin: EdgeInsets.only(left: 21, right: 21),
              // color: Color(0xffD9D9D9),
            );
          },
          itemBuilder: (context, index) {
            List<Prescriptions> prescriptionsList = prescriptionsViewModel!.prescriptionsOrderListByValue(filterType)[index].prescriptionsList!;
            return AppExpandableNotifier(
              title: prescriptionsViewModel!.prescriptionsOrderListByValue(filterType)[index].filterName,
              bodyWidget: ListView.separated(
                  shrinkWrap: true,
                  physics: NeverScrollableScrollPhysics(),
                  padding: EdgeInsets.only(bottom: 14, top: 14, left: 21, right: 21),
                  itemBuilder: (context, _index) {
                    Prescriptions prescriptions = prescriptionsList[_index];

                    bool _isSortByClinic = filterType == FilterType.Clinic;
                    return DoctorCard(
                        onTap: () async {
                          final _shouldRecallApi = await Navigator.push(
                            context,
                            FadePage(
                              page: PrescriptionItemsPage(
                                prescriptions: prescriptions,
                              ),
                            ),
                          );
                          if (_shouldRecallApi != null) {
                            showOrderLog!();
                          }
                        },
                        name: prescriptions.doctorName,
                        profileUrl: prescriptions.doctorImageURL,
                        rating: prescriptions.actualDoctorRate!.toDouble(),
                        subName: _isSortByClinic ? prescriptions.name : prescriptions.clinicDescription,
                        isSortByClinic: _isSortByClinic,
                        isInOutPatient: prescriptions.isInOutPatient,
                        isLiveCareAppointment: prescriptions.isLiveCareAppointment,
                        date: DateUtil.convertStringToDate(prescriptions.appointmentDate!) //projectViewModel.isArabic? DateUtil.getMonthDayYearDateFormattedAr( DateUtil.convertStringToDate(prescriptions.appointmentDate) ):DateUtil.getMonthDayYearDateFormatted(DateUtil.convertStringToDate(prescriptions.appointmentDate)),
                        );
                  },
                  separatorBuilder: (context, index) => SizedBox(height: 14),
                  itemCount: prescriptionsList.length),
            );
          },
          itemCount: prescriptionsViewModel!.prescriptionsOrderListByValue(filterType).length,
        ));
  }
}
