import 'package:hmg_patient_app/core/model/ImagesInfo.dart';
import 'package:hmg_patient_app/core/model/eye/AppoimentAllHistoryResult.dart';
import 'package:hmg_patient_app/core/viewModels/medical/EyeViewModel.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/theme/colors.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/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';

import '../../../uitl/gif_loader_dialog_utils.dart';
import '../../../widgets/dialogs/confirm_send_email_dialog.dart';
import 'EyeHomePage.dart';

class EyeMeasurementsPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<EyeViewModel>(
      onModelReady: (model) => model.getEyeMeasurement(),
      builder: (_, model, w) => AppScaffold(
        isShowAppBar: true,
        baseViewModel: model,
        showNewAppBar: true,
        showNewAppBarTitle: true,
        backgroundColor: CustomColors.appBackgroudGreyColor,
        description: TranslationBase.of(context).infoEye,
        imagesInfo: [
          ImagesInfo(
              imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/eye-measurements/ar/0.png',
              imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/eye-measurements/en/0.png')
        ],
        appBarTitle: TranslationBase.of(context).eyeMeasurements,
        body: SingleChildScrollView(
          child: Column(
            children: [
              ListView.separated(
                physics: NeverScrollableScrollPhysics(),
                shrinkWrap: true,
                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<AppoimentAllHistoryResultList> _appointmentAllHistoryResultList = model.appointmentFilter[index].appointmentAllHistoryResultList;
                  return AppExpandableNotifier(
                    title: model.appointmentFilter[index].filterName,
                    bodyWidget: ListView.separated(
                        shrinkWrap: true,
                        physics: NeverScrollableScrollPhysics(),
                        padding: EdgeInsets.only(bottom: 14, top: 14, left: 21, right: 21),
                        itemBuilder: (context, _index) {
                          AppoimentAllHistoryResultList _appointmentResult = _appointmentAllHistoryResultList[_index];

                          return DoctorCard(
                              onTap: () => Navigator.push(
                                context,
                                FadePage(
                                  page: EyeHomePage(
                                    appointmentAllHistoryResultList: _appointmentResult,
                                  ),
                                ),
                              ),
                            onEmailTap: () {
                              showConfirmMessage(context, () async {
                                GifLoaderDialogUtils.showMyDialog(context);
                                await model.sendGlassesPrescriptionEmail(
                                    appointmentNo: _appointmentResult!.appointmentNo!,
                                    projectName: _appointmentResult!.projectName!,
                                    projectID:  _appointmentResult!.projectID!);
                                GifLoaderDialogUtils.hideDialog(context);
                              }, projectViewModel!.user!.emailAddress!);
                            },
                              isInOutPatient: _appointmentResult.isInOutPatient,
                              name: _appointmentResult.doctorTitle! + " " + _appointmentResult.doctorNameObj!,
                                 // billNo: "appointmentResult.do",
                              profileUrl: _appointmentResult.doctorImageURL,
                              subName: _appointmentResult.clinicName,
                              isLiveCareAppointment: _appointmentResult.isLiveCareAppointment,
                              date: DateUtil.convertStringToDate(_appointmentResult.appointmentDate!),
                              isSortByClinic: false,
                              rating: _appointmentResult.actualDoctorRate! + 0.0,
                              // appointmentTime: _appointmentResult.startTime.substring(0, 5),
                              // remainingTimeInMinutes: (_appointmentResult.patientStatusType == AppointmentType.BOOKED || _appointmentResult.patientStatusType == AppointmentType.CONFIRMED)
                              //     ? _appointmentResult.remaniningHoursTocanPay
                              //     : null

                              //projectViewModel.isArabic ? DateUtil.getMonthDayYearDateFormattedAr(labOrder.orderDate) : DateUtil.getMonthDayYearDateFormatted(labOrder.orderDate),
                              );
                        },
                        separatorBuilder: (context, index) => SizedBox(height: 14),
                        itemCount: _appointmentAllHistoryResultList.length),
                  );
                },
                itemCount: model.appointmentFilter.length,
              ),

            ],
          ),
        ),
      ),
    );
  }
  void showConfirmMessage(BuildContext context, GestureTapCallback onTap, String email) {
    showDialog(
      context: context,
      builder: (cxt) => ConfirmSendEmailDialog(
        email: email,
        onTapSendEmail: () {
          onTap();
        },
      ),
    );
  }

}
