import 'package:diplomaticquarterapp/core/model/prescriptions/Prescriptions.dart';
import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_report.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/extensions/string_extensions.dart';
import 'package:diplomaticquarterapp/models/header_model.dart';
import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/reminder_dialog.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/reminder_dialog_prescription.dart';
import 'package:diplomaticquarterapp/pages/medical/prescriptions/pharmacy_for_prescriptions_page.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/new_design/doctor_header.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PrescriptionDetailsPage extends StatelessWidget {
  final PrescriptionReport prescriptionReport;
  final Prescriptions prescriptions;
  PrescriptionDetailsPage({Key key, this.prescriptionReport, this.prescriptions});

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return AppScaffold(
      isShowAppBar: true,
      showNewAppBar: true,
      backgroundColor: Color(0xffF8F8F8),
      showNewAppBarTitle: true,
      appBarTitle: TranslationBase.of(context).prescriptions,
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          DoctorHeader(
            headerModel: HeaderModel(
              prescriptions.doctorName,
              prescriptions.doctorID,
              prescriptions.doctorImageURL,
              prescriptions.speciality,
              "",
              prescriptions.name,
              DateUtil.convertStringToDate(prescriptions.appointmentDate),
              DateUtil.formatDateToTime(DateUtil.convertStringToDate(prescriptions.appointmentDate)),
              prescriptions.nationalityFlagURL,
              prescriptions.doctorRate,
              prescriptions.actualDoctorRate,
              prescriptions.noOfPatientsRate,
              "",
            ),
            isNeedToShowButton: false,
          ),
          Expanded(
            child: ListView(
              physics: BouncingScrollPhysics(),
              padding: EdgeInsets.all(21),
              children: [
                Container(
                  padding: EdgeInsets.all(14),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(10.0)),
                    boxShadow: [
                      BoxShadow(
                        color: Color(0xff000000).withOpacity(.05),
                        //spreadRadius: 5,
                        blurRadius: 27,
                        offset: Offset(0, -3),
                      ),
                    ],
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Row(
                        children: <Widget>[
                          Container(
                            decoration: BoxDecoration(
                              border: Border.all(width: 1.0, color: Color(0xffEBEBEB)),
                              borderRadius: BorderRadius.all(Radius.circular(30.0)),
                            ),
                            child: ClipRRect(
                              borderRadius: BorderRadius.all(Radius.circular(30)),
                              child: Image.network(
                                prescriptionReport.imageSRCUrl,
                                fit: BoxFit.cover,
                                width: 48,
                                height: 48,
                              ),
                            ),
                          ),
                          SizedBox(width: 12),
                          Expanded(
                            child: Text(
                              (prescriptionReport.itemDescription.isNotEmpty ? prescriptionReport.itemDescription : prescriptionReport.itemDescriptionN ?? '').toLowerCase().capitalizeFirstofEach,
                              style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64),
                            ),
                          )
                        ],
                      ),
                      SizedBox(height: 12),
                      Table(border: TableBorder(horizontalInside: BorderSide(width: 1, color: Colors.black, style: BorderStyle.solid)), children: [
                        TableRow(
                          children: [
                            Utils.tableColumnTitle(TranslationBase.of(context).route, showDivider: false),
                            Utils.tableColumnTitle(TranslationBase.of(context).frequency, showDivider: false),
                            Utils.tableColumnTitle(TranslationBase.of(context).dailyDoses, showDivider: false),
                            Utils.tableColumnTitle(TranslationBase.of(context).duration, showDivider: false)
                          ],
                        ),
                        TableRow(
                          children: [
                            Utils.tableColumnValue(prescriptionReport?.routeN ?? '', isLast: true, mProjectViewModel: projectViewModel),
                            Utils.tableColumnValue(prescriptionReport?.frequencyN ?? '', isLast: true, mProjectViewModel: projectViewModel),
                            Utils.tableColumnValue(prescriptionReport?.doseDailyQuantity.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel),
                            Utils.tableColumnValue(prescriptionReport?.days.toString() ?? '', isLast: true, mProjectViewModel: projectViewModel),
                          ],
                        ),
                      ]),
                      Text(
                        TranslationBase.of(context).remarks,
                        style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.48),
                      ),
                      Text(
                        prescriptionReport.remarks,
                        style: TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: Color(0xff575757), letterSpacing: -0.4, height: 16 / 10),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Container(
            color: Colors.white,
            padding: EdgeInsets.only(top: 16, bottom: 16, right: 21, left: 21),
            child: Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                Expanded(
                  child: DefaultButton(
                    TranslationBase.of(context).availability,
                    () {
                      Navigator.push(
                        context,
                        FadePage(
                          page: PharmacyForPrescriptionsPage(
                            itemID: prescriptionReport.itemID,
                            prescriptionReport: prescriptionReport,
                          ),
                        ),
                      );
                    },
                    iconData: Icons.location_on,
                    color: Color(0xff359846),
                  ),
                ),
                SizedBox(width: 10),
                Expanded(
                  child: DefaultButton(
                    TranslationBase.of(context).addReminder,
                    () {
                      DateTime startDate = DateTime.now();
                      DateTime endDate = DateTime(startDate.year, startDate.month, startDate.day + prescriptionReport.days);

                      showReminderDialog(
                        context,
                        endDate,
                        "",
                        prescriptionReport.itemID.toString(),
                        "",
                        "",
                        title: "${prescriptionReport.itemDescriptionN} Prescription Reminder",
                        description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ",
                        onSuccess: () {
                          AppToast.showSuccessToast(message: TranslationBase.of(context).reminderSuccess);
                        },
                      );
                      return;

                      showGeneralDialog(
                          barrierColor: Colors.black.withOpacity(0.5),
                          transitionBuilder: (context, a1, a2, widget) {
                            final curvedValue = Curves.easeInOutBack.transform(a1.value) - 1.0;
                            return Transform(
                              transform: Matrix4.translationValues(0.0, curvedValue * 200, 0.0),
                              child: Opacity(
                                opacity: a1.value,
                                child: PrescriptionReminderDialog(
                                  eventId: prescriptionReport.itemID.toString(),
                                  title: "${prescriptionReport.itemDescriptionN} Prescription Reminder",
                                  description: "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ",
                                  startDate: startDate,
                                  endDate: endDate,
                                  location: prescriptionReport.remarks,
                                  days: 1,
                                ),
                              ),
                            );
                          },
                          transitionDuration: Duration(milliseconds: 500),
                          barrierDismissible: true,
                          barrierLabel: '',
                          context: context,
                          pageBuilder: (context, animation1, animation2) {});
                    },
                    iconData: Icons.notifications_active,
                    color: Color(0xffD02127),
                    //textColor: Color(0xff2B353E),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
