import 'package:doctor_app_flutter/core/model/Prescriptions/Prescriptions.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/core/viewModel/prescription/prescription_view_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/screens/prescription/prescriptions_items/preacription_items_widget.dart';
import 'package:doctor_app_flutter/utils/date-utils.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/app_bar/patient-profile-app-bar.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dialogs/ShowImageDialog.dart';
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class PrescriptionItemsPage extends StatelessWidget {
  final Prescriptions? prescriptions;
  final PatiantInformtion? patient;
  final String? arrivalType;

  PrescriptionItemsPage(
      {Key? key,
      this.prescriptions,
      this.patient,
      this.arrivalType});

  @override
  Widget build(BuildContext context) {
    return BaseView<PrescriptionViewModel>(
      onModelReady: (model) => model.getPrescriptionReport(
          prescriptions: prescriptions, patient: patient!),
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        backgroundColor: Colors.grey[100]!,
        baseViewModel: model,
        appBar: PatientProfileAppBar(
          patient!,
          clinic: prescriptions!.clinicDescription!,
          branch: prescriptions!.name!,
          isPrescriptions: true,
          appointmentDate: AppDateUtils.getDateTimeFromServerFormat(
              prescriptions!.appointmentDate!),
          doctorName: prescriptions!.doctorName!,
          profileUrl: prescriptions!.doctorImageURL!,
          isAppointmentHeader: true,
        ),
        // Use a Column with Expanded ListView to give the list a bounded height
        // and avoid RenderFlex overflow from nested scrolling widgets.
        body: Column(
          children: [
            Expanded(
              child: ListView.builder(
                padding: EdgeInsets.zero,
                itemCount: model.prescriptionReportEnhList.length,
                itemBuilder: (context, index) => PrescriptionItemsWidget(
                  frequency: model.prescriptionReportEnhList[index].frequency,
                  itemDescription: model.prescriptionReportEnhList[index].itemDescription,
                  days: model.prescriptionReportEnhList[index].days,
                  route: model.prescriptionReportEnhList[index].route,
                  dailyDoses: model.prescriptionReportEnhList[index].doseDailyQuantity,
                  imageSRCUrl: model.prescriptionReportEnhList[index].imageSRCUrl,
                  remarks: model.prescriptionReportEnhList[index].remarks,
                  prescriptionViewModel: model,
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
