import 'package:diplomaticquarterapp/core/model/prescriptions/prescriptions_order.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/prescriptions_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/BottomButton.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_dialog.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class PrescriptionsHistoryDetailsPage extends StatelessWidget {
  final PrescriptionsOrder prescriptionsOrder;

  PrescriptionsHistoryDetailsPage({Key key, this.prescriptionsOrder});

  @override
  Widget build(BuildContext context) {
    return BaseView<PrescriptionsViewModel>(
      onModelReady: (model) => model.getPrescriptionReportEnh(
          prescriptionsOrder: prescriptionsOrder),
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).orderDetails,
        baseViewModel: model,
        body: SingleChildScrollView(
          child: Container(
            margin: EdgeInsets.all(15.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(
                  height: 5,
                ),
                Container(
                  width: double.infinity,
                    decoration: BoxDecoration(
                        color: prescriptionsOrder.status == 3 ?Colors.green : prescriptionsOrder.status ==2 ? Colors.grey: Colors.red,
                        borderRadius: BorderRadius.circular(5)),
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Texts(TranslationBase.of(context).orderStatus +' : ${prescriptionsOrder.descriptionN}',color: Colors.white,),
                    )),
                SizedBox(
                  height: 15,
                ),
                Table(
                  border: TableBorder.symmetric(
                      inside: BorderSide(width: 0.5),
                      outside: BorderSide(width: 0.5)),
                  children: [
                    TableRow(children: [
                      Container(
                        height: 50,
                        color: Colors.white,
                        child: Center(
                          child: Texts(TranslationBase.of(context).orderNo),
                        ),
                      ),
                      Container(
                        height: 50,
                        color: Colors.white,
                        child: Center(
                          child: Texts(TranslationBase.of(context).date),
                        ),
                      ),
                    ]),
                    TableRow(children: [
                      Container(
                        height: 70,
                        color: Colors.white,
                        child: Center(
                          child: Texts('${prescriptionsOrder.iD}'),
                        ),
                      ),
                      Container(
                        height: 70,
                        color: Colors.white,
                        child: Center(
                          child: Texts('${prescriptionsOrder.createdOn.year}-${prescriptionsOrder.createdOn.day}-${prescriptionsOrder.createdOn.day} ${prescriptionsOrder.createdOn.hour}:${prescriptionsOrder.createdOn.minute}'),
                        ),
                      ),
                    ])
                  ],
                ),
                SizedBox(
                  height: 15,
                ),
                ...List.generate(
                  model.prescriptionReportEnhList.length,
                  (index) => Container(
                    margin: EdgeInsets.all(8.0),
                    color: Colors.white,
                    child: Row(
                      children: <Widget>[
                        ClipRRect(
                          borderRadius: BorderRadius.all(Radius.circular(5)),
                          child: Image.network(
                            model.prescriptionReportEnhList[index].imageSRCUrl,
                            fit: BoxFit.cover,
                            width: 60,
                            height: 70,
                          ),
                        ),
                        Expanded(
                          child: Padding(
                            padding: const EdgeInsets.all(8.0),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                Texts(model.prescriptionReportEnhList[index]
                                    .itemDescription),
                              ],
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
                SizedBox(height: 120,)
              ],
            ),
          ),
        ),
        bottomSheet: Container(
          //padding: EdgeInsets.all(8.0),
          // margin: EdgeInsets.all(8.0),
          child: BottomButton(
            label: TranslationBase.of(context).cancelOrder,
            disabled: prescriptionsOrder.status != 1,
            textColor: Colors.white,
            onTap: (){

              showCDialog(model,context);
              //showAlertDialog(context);
            },
          ),
        ),
      ),
    );
  }

  showCDialog(PrescriptionsViewModel model,context){
    ConfirmDialog(
        context: context,
        confirmMessage: "Are you sure ?",
        okText: TranslationBase.of(context).confirm,
        cancelText: TranslationBase.of(context).cancel,
        okFunction: ()  {
          Navigator.of(context).pop();
          model.updatePressOrder(presOrderID: prescriptionsOrder.iD).then((value) {
            Navigator.of(context).pop();
          });
        },
        cancelFunction: () => {}).showAlertDialog(context);
    // dialog.showAlertDialog(context);
  }

}
