import 'package:doctor_app_flutter/core/model/Prescriptions/get_medication_for_inpatient_model.dart';
import 'package:doctor_app_flutter/core/viewModel/prescription/prescription_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.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/user-guid/CusomRow.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PrescriptionItemsInPatientPage extends StatelessWidget {
  final GetMedicationForInPatientModel? prescriptions;
  final PatiantInformtion? patient;
  final String?patientType;
  final String? arrivalType;
  final DateTime? startOn;
  final DateTime? stopOn;
  final int? prescriptionIndex;
  final bool isVidaPlusProject;

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

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<PrescriptionViewModel>(
      onModelReady: (model) async {
        if (model.medicationForInPatient.length == 0) {
          await model.getMedicationForInPatient(patient!,isVidaPlusProject);
        }
      },
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        backgroundColor: Colors.grey[100]!,
        baseViewModel: model,
        appBar: PatientProfileAppBar(patient!),
        body: SingleChildScrollView(
          child: Container(
            child: Column(
              children: [
                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(
                            prescriptions!.pHRItemDescription ?? "",
                            bold: true,
                          ),
                        ),
                        SizedBox(
                          height: 12,
                        ),
                        Row(
                          mainAxisAlignment: MainAxisAlignment.start,
                          crossAxisAlignment: CrossAxisAlignment.center,
                          children: [
                            SizedBox(
                              width: 18,
                            ),
                            SizedBox(
                              width: 10,
                            ),
                            Expanded(
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  CustomRow(
                                    label: TranslationBase.of(context).direction + ' :',
                                    value: " " + prescriptions!.directionDescription! ?? "",
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                  CustomRow(
                                    label: TranslationBase.of(context).route + ' :',
                                    value: " " + prescriptions!.routeDescription! ?? '',
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                  CustomRow(
                                    label: TranslationBase.of(context).refill + ' :',
                                    value: " " + prescriptions!.refillDescription! ?? '',
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                  CustomRow(
                                    label: TranslationBase.of(context).startDate + ' :',
                                    value: " " + AppDateUtils.getDayMonthYearDateFormatted(startOn!, isArabic: projectViewModel.isArabic) ?? '',
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                  CustomRow(
                                    label: TranslationBase.of(context).stopDate + ' :',
                                    value: " " + AppDateUtils.getDayMonthYearDateFormatted(stopOn!, isArabic: projectViewModel.isArabic) ?? '',
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                  CustomRow(
                                    label: 'UOM' + ' :',
                                    value: " " + prescriptions!.uomDescription.toString() ?? '',
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                  CustomRow(
                                    label: TranslationBase.of(context).dailyDoses,
                                    value: " " + prescriptions!.dose.toString() ?? '',
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                  CustomRow(
                                    label: TranslationBase.of(context).status,
                                    value: " " + prescriptions!.statusDescription.toString() ?? '',
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                  CustomRow(
                                    label: TranslationBase.of(context).processed,
                                    value: " " + prescriptions!.doctorName.toString() ?? '',
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                  SizedBox(
                                    height: 12,
                                  ),
                                  CustomRow(
                                    label: '',
                                    value: prescriptions!.comments ?? '',
                                    isCopyable: false,
                                    isExpanded: false,
                                    valueSize: 13,
                                    labelSize: 13,
                                  ),
                                ],
                              ),
                            )
                          ],
                        )
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
