import 'package:doctor_app_flutter/core/model/Prescriptions/prescription_in_patient.dart';
import 'package:doctor_app_flutter/core/viewModel/prescription_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/util/date-utils.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-profile-header-new-design-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:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PrescriptionItemsInPatientPage extends StatelessWidget {
  final PrescriotionInPatient prescriptions;
  final PatiantInformtion patient;
  final String patientType;
  final String arrivalType;
  final DateTime startOn;
  final DateTime stopOn;
  final int prescriptionIndex;

  PrescriptionItemsInPatientPage(
      {Key key,
      this.prescriptions,
      this.patient,
      this.patientType,
      this.arrivalType,
      this.stopOn,
      this.startOn,
      this.prescriptionIndex});

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<PrescriptionViewModel>(
      onModelReady: (model) async {
        if (model.inPatientPrescription.length == 0) {
          await model.getPrescriptionsInPatient(patient);
        }
      },
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        backgroundColor: Colors.grey[100],
        baseViewModel: model,
        appBar: PatientProfileHeaderNewDesignAppBar(
            patient, patient.patientType.toString(), patient.arrivedOn),
        body: SingleChildScrollView(
          child: Container(
            child: Column(
              children: [
                // if (!prescriptions.isInOutPatient)
                //   ...List.generate(
                //       model.prescriptionReportList.length,
                //       (index) => Container(
                //             decoration: BoxDecoration(
                //               borderRadius: BorderRadius.circular(12),
                //               color: Colors.white,
                //             ),
                //             margin: EdgeInsets.all(12),
                //             child: Padding(
                //               padding: const EdgeInsets.all(8.0),
                //               child: Column(
                //                 crossAxisAlignment: CrossAxisAlignment.start,
                //                 children: [
                //                   Container(
                //                       margin:
                //                           EdgeInsets.only(left: 18, right: 18),
                //                       child: AppText(
                //                         model.prescriptionReportList[index]
                //                                 .itemDescription.isNotEmpty
                //                             ? model
                //                                 .prescriptionReportList[index]
                //                                 .itemDescription
                //                             : model
                //                                 .prescriptionReportList[index]
                //                                 .itemDescriptionN,
                //                         bold: true,
                //                       )),
                //                   SizedBox(
                //                     height: 12,
                //                   ),
                //                   Row(
                //                     children: [
                //                       SizedBox(
                //                         width: 18,
                //                       ),
                //                       Container(
                //                         decoration: BoxDecoration(
                //                             shape: BoxShape.circle,
                //                             border: Border.all(
                //                                 width: 0.5,
                //                                 color: Colors.grey)),
                //                         height: 55,
                //                         width: 55,
                //                         child: InkWell(
                //                           onTap: () {
                //                             showDialog(
                //                                 context: context,
                //                                 child: ShowImageDialog(
                //                                   imageUrl: model
                //                                       .prescriptionReportEnhList[
                //                                           index]
                //                                       .imageSRCUrl,
                //                                 ));
                //                           },
                //                           child: Padding(
                //                             padding: const EdgeInsets.all(8.0),
                //                             child: Image.network(
                //                               model
                //                                   .prescriptionReportList[index]
                //                                   .imageSRCUrl,
                //                               fit: BoxFit.cover,
                //                             ),
                //                           ),
                //                         ),
                //                       ),
                //                       SizedBox(
                //                         width: 10,
                //                       ),
                //                       Expanded(
                //                         child: Column(
                //                           crossAxisAlignment:
                //                               CrossAxisAlignment.start,
                //                           children: [
                //                             Row(
                //                               children: [
                //                                 AppText(
                //                                   TranslationBase.of(context)
                //                                       .route,
                //                                   color: Colors.grey,
                //                                 ),
                //                                 Expanded(
                //                                     child: AppText(" " +
                //                                         model
                //                                             .prescriptionReportList[
                //                                                 index]
                //                                             .routeN)),
                //                               ],
                //                             ),
                //                             Row(
                //                               children: [
                //                                 AppText(
                //                                   TranslationBase.of(context)
                //                                       .frequency,
                //                                   color: Colors.grey,
                //                                 ),
                //                                 AppText(" " +
                //                                         model
                //                                             .prescriptionReportList[
                //                                                 index]
                //                                             .frequencyN ??
                //                                     ''),
                //                               ],
                //                             ),
                //                             Row(
                //                               children: [
                //                                 AppText(
                //                                   TranslationBase.of(context)
                //                                       .dailyDoses,
                //                                   color: Colors.grey,
                //                                 ),
                //                                 AppText(" " +
                //                                         model
                //                                             .prescriptionReportList[
                //                                                 index]
                //                                             .doseDailyQuantity ??
                //                                     ''),
                //                               ],
                //                             ),
                //                             Row(
                //                               children: [
                //                                 AppText(
                //                                   TranslationBase.of(context)
                //                                       .duration,
                //                                   color: Colors.grey,
                //                                 ),
                //                                 AppText(" " +
                //                                         model
                //                                             .prescriptionReportList[
                //                                                 index]
                //                                             .days
                //                                             .toString() ??
                //                                     ''),
                //                               ],
                //                             ),
                //                             SizedBox(
                //                               height: 12,
                //                             ),
                //                             AppText(model
                //                                     .prescriptionReportList[
                //                                         index]
                //                                     .remarks ??
                //                                 ''),
                //                           ],
                //                         ),
                //                       )
                //                     ],
                //                   )
                //                 ],
                //               ),
                //             ),
                //           ))
                // else

                Container(
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(12),
                    color: Colors.white,
                  ),
                  margin: EdgeInsets.all(12),
                  child: Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          margin: EdgeInsets.only(left: 18, right: 18),
                          child: AppText(
                            model.inPatientPrescription[prescriptionIndex]
                                .itemDescription,
                            bold: true,
                          ),
                        ),
                        SizedBox(
                          height: 12,
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            SizedBox(
                              width: 18,
                            ),
                            // Container(
                            //   decoration: BoxDecoration(
                            //       shape: BoxShape.circle,
                            //       border: Border.all(
                            //           width: 0.5, color: Colors.grey)),
                            //   height: 55,
                            //   width: 55,
                            //   child: InkWell(
                            //     onTap: () {
                            //       showDialog(
                            //         context: context,
                            //         // child: ShowImageDialog(
                            //         //   imageUrl: model
                            //         //       .inPatientPrescription[index]
                            //         //       .imageSRCUrl,
                            //         // ),
                            //       );
                            //     },
                            //     child: Padding(
                            //       padding: const EdgeInsets.all(8.0),
                            //       // child: Image.network(
                            //       //   model.prescriptionReportEnhList[index]
                            //       //       .imageSRCUrl,
                            //       //   fit: BoxFit.cover,
                            //       // ),
                            //     ),
                            //   ),
                            // ),
                            SizedBox(
                              width: 10,
                            ),
                            Expanded(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Row(
                                    children: [
                                      AppText(
                                        'Direction',
                                        color: Colors.grey,
                                      ),
                                      Expanded(
                                          child: AppText(" " +
                                                  model
                                                      .inPatientPrescription[
                                                          prescriptionIndex]
                                                      .direction ??
                                              '')),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      AppText(
                                        'Route',
                                        color: Colors.grey,
                                      ),
                                      AppText(" " +
                                              model
                                                  .inPatientPrescription[
                                                      prescriptionIndex]
                                                  .route
                                                  .toString() ??
                                          ''),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      AppText(
                                        'Refill',
                                        color: Colors.grey,
                                      ),
                                      Expanded(
                                          child: AppText(" " +
                                                  model
                                                      .inPatientPrescription[
                                                          prescriptionIndex]
                                                      .refillType ??
                                              '')),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      AppText(
                                        'Start Date ',
                                        color: Colors.grey,
                                      ),
                                      Expanded(
                                        child: AppText(
                                          '${DateUtils.getDayMonthYearDateFormatted(startOn, isArabic: projectViewModel.isArabic)}',
                                          color: Colors.black,
                                          fontWeight: FontWeight.w600,
                                          fontSize: 14,
                                        ),
                                      ),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      AppText(
                                        'Stop Date',
                                        color: Colors.grey,
                                      ),
                                      Expanded(
                                        child: AppText(
                                          '${DateUtils.getDayMonthYearDateFormatted(stopOn, isArabic: projectViewModel.isArabic)}',
                                          color: Colors.black,
                                          fontWeight: FontWeight.w600,
                                          fontSize: 14,
                                        ),
                                      ),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      AppText(
                                        'UOM',
                                        color: Colors.grey,
                                      ),
                                      AppText(" " +
                                              model
                                                  .inPatientPrescription[
                                                      prescriptionIndex]
                                                  .unitofMeasurementDescription ??
                                          ''),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      AppText(
                                        TranslationBase.of(context).dailyDoses,
                                        color: Colors.grey,
                                      ),
                                      AppText(" " +
                                              model
                                                  .inPatientPrescription[
                                                      prescriptionIndex]
                                                  .dose
                                                  .toString() ??
                                          ''),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      AppText(
                                        'Status',
                                        color: Colors.grey,
                                      ),
                                      AppText(" " +
                                              model
                                                  .inPatientPrescription[
                                                      prescriptionIndex]
                                                  .statusDescription
                                                  .toString() ??
                                          ''),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      AppText(
                                        'Processed',
                                        color: Colors.grey,
                                      ),
                                      AppText(" " +
                                              model
                                                  .inPatientPrescription[
                                                      prescriptionIndex]
                                                  .processedBy ??
                                          ''),
                                    ],
                                  ),
                                  Row(
                                    children: [
                                      AppText(
                                        TranslationBase.of(context).dailyDoses,
                                        color: Colors.grey,
                                      ),
                                      AppText(" " +
                                              model
                                                  .inPatientPrescription[
                                                      prescriptionIndex]
                                                  .dose
                                                  .toString() ??
                                          ''),
                                    ],
                                  ),
                                  SizedBox(
                                    height: 12,
                                  ),
                                  AppText(model
                                          .inPatientPrescription[
                                              prescriptionIndex]
                                          .comments ??
                                      ''),
                                ],
                              ),
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
