import 'package:diplomaticquarterapp/core/viewModels/ancillary_orders_view_model.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrdersDetails.dart';
import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/health_calculator/calorie_calculator/calorie_calculator.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';

class AnicllaryOrders extends StatefulWidget {
  @override
  _AnicllaryOrdersState createState() => _AnicllaryOrdersState();
}

class _AnicllaryOrdersState extends State<AnicllaryOrders>
    with SingleTickerProviderStateMixin {
  TabController _tabController;
  void initState() {
    super.initState();
    _tabController = TabController(length: 2, vsync: this);
  }

  void dispose() {
    super.dispose();
    _tabController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return BaseView<AnciallryOrdersViewModel>(
        onModelReady: (model) => model.getOrders(),
        builder: (_, model, widget) => AppScaffold(
            isShowAppBar: true,
            baseViewModel: model,
            appBarTitle: TranslationBase.of(context).anicllaryOrders,
            body: SingleChildScrollView(
                padding: EdgeInsets.all(12),
                child: model.ancillaryLists.length > 0
                    ? Column(children: [
                        getPatientInfo(model),
                        getAncillaryOrdersList(model)
                      ])
                    : SizedBox())));
  }

  Widget getPatientInfo(AnciallryOrdersViewModel model) {
    print(model.ancillaryLists);
    return Padding(
      child: Column(
        children: [
          Row(
            children: [
              Texts(
                TranslationBase.of(context).mrn,
                fontWeight: FontWeight.bold,
                fontSize: 22,
              ),
              Texts(
                " : ",
                fontSize: 20,
              ),
              Texts(
                model.ancillaryLists[0].patientID.toString(),
              )
            ],
          ),
          Row(
            children: [
              Texts(
                TranslationBase.of(context).patientName,
                fontWeight: FontWeight.bold,
                fontSize: 20,
              ),
              Texts(
                " : ",
                fontSize: 20,
              ),
              Texts(
                model.ancillaryLists[0].patientName,
              )
            ],
          ),
          Divider()
        ],
      ),
      padding: EdgeInsets.only(top: 5.0, bottom: 10.0),
    );
  }

  Widget getAncillaryOrdersList(AnciallryOrdersViewModel model) {
    return Column(
        children: model.ancillaryLists[0].ancillaryOrderList
            .map(
              (item) => InkWell(
                  onTap: () {
                    ancillaryOrdersDetails(item, model.ancillaryLists[0].projectID);
                  },
                  child: Container(
                      decoration: BoxDecoration(
                          border: Border(
                              bottom: BorderSide(
                        width: 0.5,
                      ))),
                      padding: EdgeInsets.all(15),
                      child: Row(
                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
                          children: [
                            Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  Padding(
                                      padding: EdgeInsets.all(3),
                                      child: Row(
                                        mainAxisAlignment:
                                            MainAxisAlignment.start,
                                        children: [
                                          Texts(
                                            TranslationBase.of(context)
                                                    .appointmentNo +
                                                ' : ',
                                            fontWeight: FontWeight.bold,
                                          ),
                                          Texts(item.appointmentNo.toString())
                                        ],
                                      )),
                                  Padding(
                                      padding: EdgeInsets.all(3),
                                      child: Row(
                                        children: [
                                          Texts(
                                              TranslationBase.of(context)
                                                      .appointmentDate +
                                                  ' : ',
                                              fontWeight: FontWeight.bold),
                                          Texts(DateUtil.getFormattedDate(
                                              DateUtil.convertStringToDate(
                                                  item.appointmentDate),
                                              "MMM dd,yyyy"))
                                        ],
                                      )),
                                  Padding(
                                      padding: EdgeInsets.all(3),
                                      child: Row(
                                        children: [
                                          Texts(
                                              TranslationBase.of(context)
                                                      .doctorName +
                                                  ' : ',
                                              fontWeight: FontWeight.bold),
                                          Texts(item.doctorName.toString())
                                        ],
                                      )),
                                  Divider(
                                    color: Colors.black12,
                                    height: 1,
                                  )
                                ]),
                            Icon(
                              Icons.arrow_right,
                              size: 25,
                            )
                          ]))),
            )
            .toList());
  }

  ancillaryOrdersDetails(item, projectId) {
    Navigator.push(
      context,
      FadePage(
        page: AnicllaryOrdersDetails(item.appointmentNo, item.orderNo,projectId ),
      ),
    );
  }
}
