import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_report.dart';
import 'package:diplomaticquarterapp/core/model/prescriptions/prescription_report_inp.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/MyAppointments/widgets/reminder_dialog.dart';
import 'package:diplomaticquarterapp/pages/medical/prescriptions/pharmacy_for_prescriptions_page.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.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 PrescriptionDetailsPageINP extends StatelessWidget {
  final PrescriptionReportINP prescriptionReport;

  PrescriptionDetailsPageINP({Key key, this.prescriptionReport});

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      isShowAppBar: true,
      appBarTitle: TranslationBase.of(context).prescriptions,
      body: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Container(
              width: double.infinity,
              margin: EdgeInsets.only(top: 10, left: 10, right: 10),
              padding: EdgeInsets.all(8.0),
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.all(
                  Radius.circular(10.0),
                ),
                border: Border.all(color: Colors.grey[200], width: 0.5),
              ),
              child: Row(
                children: <Widget>[
                  ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(5)),
                    child: Image.network(
                      prescriptionReport.imageSRCUrl,
                      fit: BoxFit.cover,
                      width: 60,
                      height: 70,
                    ),
                  ),
                  Expanded(
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Center(
                        child: Texts(prescriptionReport.itemDescription.isNotEmpty
                            ? prescriptionReport.itemDescription
                            : prescriptionReport.itemDescriptionN ?? ''),
                      ),
                    ),
                  )
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.all(8),
              child: Row(
                children: [
                  Expanded(
                    child: InkWell(
                        onTap: () => Navigator.push(
                              context,
                              FadePage(
                                page: PharmacyForPrescriptionsPage(
                                  itemID: prescriptionReport.itemID,
                                ),
                              ),
                            ),
                        child: Center(
                          child: Column(
                            children: <Widget>[
                              Container(
                                width: 50,
                                decoration: BoxDecoration(color: Colors.white, shape: BoxShape.rectangle),
                                child: Column(
                                  children: <Widget>[
                                    Icon(
                                      Icons.pin_drop,
                                      color: Colors.red[800],
                                      size: 55,
                                    ),
                                  ],
                                ),
                              ),
                              SizedBox(
                                height: 5,
                              ),
                              Texts(TranslationBase.of(context).availability)
                            ],
                          ),
                        )),
                  ),
                  _addReminderButton(context)
                ],
              ),
            ),
            Container(
              color: Colors.white,
              margin: EdgeInsets.only(top: 10, left: 10, right: 10),
              child: Table(
                border: TableBorder.symmetric(inside: BorderSide(width: 0.5), outside: BorderSide(width: 0.5)),
                children: [
                  TableRow(
                    children: [
                      Container(
                          color: Colors.white,
                          height: 40,
                          width: double.infinity,
                          child: Center(
                              child: Texts(
                            TranslationBase.of(context).route,
                            fontSize: 14,
                          ))),
                      Container(
                          color: Colors.white,
                          height: 40,
                          width: double.infinity,
                          child: Center(
                              child: Texts(
                            TranslationBase.of(context).frequency,
                            fontSize: 14,
                          ))),
                      Container(
                          color: Colors.white,
                          height: 40,
                          width: double.infinity,
                          padding: EdgeInsets.symmetric(horizontal: 4),
                          child: Center(
                              child: Texts(
                            "${TranslationBase.of(context).dailyDoses}",
                            fontSize: 14,
                          ))),
                      Container(
                          color: Colors.white,
                          height: 40,
                          width: double.infinity,
                          child: Center(
                              child: Texts(
                            TranslationBase.of(context).duration,
                            fontSize: 14,
                          ))),
                    ],
                  ),
                  TableRow(
                    children: [
                      Container(
                          color: Colors.white,
                          height: 50,
                          width: double.infinity,
                          child: Center(child: Text(prescriptionReport.routeN ?? ''))),
                      Container(
                          color: Colors.white,
                          height: 50,
                          width: double.infinity,
                          child: Center(child: Text(prescriptionReport.frequencyN ?? ''))),
                      Container(
                          color: Colors.white,
                          height: 50,
                          width: double.infinity,
                          child: Center(child: Text('${prescriptionReport.doseDailyQuantity}'))),
                      Container(
                          color: Colors.white,
                          height: 50,
                          width: double.infinity,
                          child: Center(child: Text('${prescriptionReport.days}')))
                    ],
                  ),
                ],
              ),
            ),
            Container(
              margin: EdgeInsets.only(top: 10, left: 10, right: 10),
              width: double.infinity,
              color: Colors.white,
              padding: EdgeInsets.all(5),
              child: Center(
                child: Column(
                  children: <Widget>[
                    Texts(TranslationBase.of(context).notes),
                    SizedBox(
                      height: 5,
                    ),
                    Divider(
                      height: 0.5,
                      color: Colors.grey[300],
                    ),
                    SizedBox(
                      height: 5,
                    ),
                    Texts(prescriptionReport.remarks ?? ''),
                  ],
                ),
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget _addReminderButton(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);

    return GestureDetector(
      onTap: () {
        DateTime startDate = DateTime.now();
        DateTime endDate = DateTime(startDate.year, startDate.month, startDate.day + prescriptionReport.days);

        print(prescriptionReport);
        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: ReminderDialog(
                    eventId: prescriptionReport.itemID.toString(),
                    title: "Prescription Reminder",
                    description:
                        "${prescriptionReport.itemDescriptionN} ${prescriptionReport.frequencyN} ${prescriptionReport.routeN} ",
                    startDate: "/Date(${startDate.millisecondsSinceEpoch}+0300)/",
                    endDate: "/Date(${endDate.millisecondsSinceEpoch}+0300)/",
                    location: prescriptionReport.remarks,
                  ),
                ),
              );
            },
            transitionDuration: Duration(milliseconds: 500),
            barrierDismissible: true,
            barrierLabel: '',
            context: context,
            pageBuilder: (context, animation1, animation2) {});
      },
      child: Column(
        mainAxisSize: MainAxisSize.max,
        children: [
          Container(
            // height: 100.0,
            margin: EdgeInsets.all(7.0),
            padding: EdgeInsets.only(bottom: 4.0),
            decoration: BoxDecoration(
                boxShadow: [BoxShadow(color: Colors.grey[400], blurRadius: 2.0, spreadRadius: 0.0)],
                borderRadius: BorderRadius.circular(10),
                color: Colors.white),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.fromLTRB(5.0, 5.0, 5.0, 0.0),
                  child: Text("add",
                      overflow: TextOverflow.clip,
                      style: TextStyle(color: new Color(0xffB8382C), letterSpacing: 1.0, fontSize: 18.0)),
                ),
                Container(
                  margin: EdgeInsets.fromLTRB(5.0, 0.0, 5.0, 0.0),
                  child: Text("reminder",
                      overflow: TextOverflow.clip,
                      style: TextStyle(color: Colors.black, letterSpacing: 1.0, fontSize: 15.0)),
                ),
                Container(
                  alignment: projectViewModel.isArabic ? Alignment.bottomLeft : Alignment.bottomRight,
                  margin: projectViewModel.isArabic
                      ? EdgeInsets.fromLTRB(10.0, 7.0, 0.0, 8.0)
                      : EdgeInsets.fromLTRB(0.0, 7.0, 10.0, 8.0),
                  child: Image.asset("assets/images/new-design/reminder_icon.png", width: 45.0, height: 45.0),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
