import 'package:auto_size_text/auto_size_text.dart';
import 'package:hmg_patient_app/core/enum/patient_lookup.dart';
import 'package:hmg_patient_app/core/model/ImagesInfo.dart';
import 'package:hmg_patient_app/core/viewModels/medical/vital_sign_view_model.dart';
import 'package:hmg_patient_app/models/vital_sign.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/pages/medical/vital_sign/vital_sign_item.dart';
import 'package:hmg_patient_app/pages/medical/vital_sign/vital_sign_item_details_screen.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:hmg_patient_app/widgets/data_display/text.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:hmg_patient_app/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

class VitalSignDetailsScreen extends StatelessWidget {
  static const String url = "assets/images/";

  int? appointmentNo;
  int? projectID;
  bool isNotOneAppointment;

  VitalSignDetailsScreen({this.appointmentNo, this.projectID, this.isNotOneAppointment = true});

  List<ImagesInfo> imagesInfo =[];
  List<VitalSign> vitalSigns = [];

  initList(BuildContext context, VitalSignViewModel mode) {
    vitalSigns.clear();
    vitalSigns.add(new VitalSign(TranslationBase.of(context).height, mode.heightCm, TranslationBase.of(context).cm, "assets/images/new/height.svg"));
    vitalSigns.add(new VitalSign(TranslationBase.of(context).weight, mode.weightKg, TranslationBase.of(context).kg, "assets/images/new/weight.svg"));
    // vitalSigns.add(new VitalSign(TranslationBase.of(context).body, mode.bodyMax, TranslationBase.of(context).mass, "assets/images/new/"));
    vitalSigns.add(new VitalSign(TranslationBase.of(context).temperature, mode.temperatureCelcius, TranslationBase.of(context).tempC, "assets/images/new/temperature.svg"));
    vitalSigns.add(new VitalSign(TranslationBase.of(context).heart, mode.hartRat, TranslationBase.of(context).bpm, "assets/images/new/heart_rate.svg"));
    vitalSigns.add(new VitalSign(TranslationBase.of(context).respirationRate, mode.respirationBeatPerMinute, TranslationBase.of(context).respirationBPM, "assets/images/new/respiration_rate.svg"));
    vitalSigns.add(new VitalSign(TranslationBase.of(context).bloodPressure, mode.bloodPressure, TranslationBase.of(context).sysDias, "assets/images/new/blood_pressure.svg"));
  }

  @override
  Widget build(BuildContext context) {
    imagesInfo.add(ImagesInfo(
        imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/my-vital-signs/en/0.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/my-vital-signs/ar/0.png'));
    imagesInfo.add(ImagesInfo(
        imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/my-vital-signs/en/1.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/my-vital-signs/ar/1.png'));
    return BaseView<VitalSignViewModel>(
      onModelReady: appointmentNo != null && projectID != null ? (model) => model.getPatientVitalSign(appointmentNo: appointmentNo, projectID: projectID!) : (model) => model.getPatientVitalSign(),
      builder: (_, mode, widget) {
        initList(context, mode);
        return AppScaffold(
          isShowAppBar: true,
          appBarTitle: TranslationBase.of(context).vitalSigns,
          baseViewModel: mode,
          description: TranslationBase.of(context).infoSigns,
          imagesInfo: imagesInfo,
          showNewAppBar: true,
          showNewAppBarTitle: true,
          backgroundColor: Color(0xFFF7F7F7),
          body: mode.vitalSignResModelList.length > 0
              ? Container(
                  width: double.infinity,
                  child: ListView(
                    children: [
                      Container(
                        child: Container(
                          margin: EdgeInsets.only(left: 20, right: 20, top: 20, bottom: 6),
                          decoration: cardRadius(12),
                          child: Padding(
                            padding: const EdgeInsets.all(12.0),
                            child: Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: [
                                Text(
                                  TranslationBase.of(context).bodyMassIndex + mode.bodyMax,
                                  style: TextStyle(
                                    fontSize: 16,
                                    letterSpacing: -0.64,
                                    fontWeight: FontWeight.w600,
                                  ),
                                ),
                                mHeight(20),
                                Container(
                                  height: MediaQuery.of(context).size.width / 2.8,
                                  child: Row(
                                    children: [
                                      showMass(context, TranslationBase.of(context).underWeight, "< 18.5", double.parse(mode.bodyMax) <= 18.5 ? Colors.red : Colors.black, 8),
                                      mWidth(12),
                                      showMass(context, TranslationBase.of(context).healthy, "18.5 - 24.9", (double.parse(mode.bodyMax) > 18.5 && double.parse(mode.bodyMax) < 25) ? Colors.red : Colors.black, 6),
                                      mWidth(12),
                                      showMass(context, TranslationBase.of(context).overWeight, "25 - 29.9", (double.parse(mode.bodyMax) >= 25 && double.parse(mode.bodyMax) < 30) ? Colors.red : Colors.black, 4),
                                      mWidth(12),
                                      showMass(context, TranslationBase.of(context).obese, "30 - 34.9", (double.parse(mode.bodyMax) >= 30 && double.parse(mode.bodyMax) < 35) ? Colors.red : Colors.black, 2),
                                      mWidth(12),
                                      showMass(context, TranslationBase.of(context).extremeObese, "> 35", (double.parse(mode.bodyMax) >= 35) ? Colors.red : Colors.black, 0),
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          ),
                        ),
                      ),
                      mHeight(2),
                      Container(
                        padding: EdgeInsets.only(left: 16, right: 16, bottom: 16),
                        child: GridView.builder(
                          gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 2 / 2, crossAxisSpacing: 12, mainAxisSpacing: 12),
                          itemCount: vitalSigns.length,
                          padding: EdgeInsets.all(4),
                          physics: NeverScrollableScrollPhysics(),
                          shrinkWrap: true,
                          itemBuilder: (BuildContext context, int index) {
                            return InkWell(
                              onTap: () {
                                if (index == 0) {
                                  if (isNotOneAppointment) {
                                    Navigator.push(
                                      context,
                                      FadePage(
                                        page: VitalSignItemDetailsScreen(
                                          pageKey: VitalSignDetails.Height,
                                          pageTitle: TranslationBase.of(context).height,
                                          vitalList: mode.vitalSignResModelList,
                                        ),
                                      ),
                                    );
                                  }
                                } else if (index == 1) {
                                  if (isNotOneAppointment) {
                                    Navigator.push(
                                      context,
                                      FadePage(
                                        page: VitalSignItemDetailsScreen(
                                          pageKey: VitalSignDetails.Weight,
                                          pageTitle: TranslationBase.of(context).weight,
                                          vitalList: mode.vitalSignResModelList,
                                        ),
                                      ),
                                    );
                                  }
                                } else if (index == 2) {
                                  if (isNotOneAppointment) {
                                    Navigator.push(
                                      context,
                                      FadePage(
                                        page: VitalSignItemDetailsScreen(
                                          pageKey: VitalSignDetails.Temperature,
                                          pageTitle:
                                          TranslationBase.of(context).temperature,
                                          vitalList: mode.vitalSignResModelList,

                                        ),
                                      ),
                                    );
                                  }
                                } else if (index == 3) {
                                  if (isNotOneAppointment) {
                                    Navigator.push(
                                      context,
                                      FadePage(
                                        page: VitalSignItemDetailsScreen(
                                          pageKey: VitalSignDetails.heart,
                                          pageTitle: TranslationBase.of(context).heart,
                                          vitalList: mode.vitalSignResModelList,

                                        ),
                                      ),
                                    );
                                  }
                                } else if (index == 4) {
                                  if (isNotOneAppointment) {
                                    Navigator.push(
                                      context,
                                      FadePage(
                                        page: VitalSignItemDetailsScreen(
                                          pageKey: VitalSignDetails.Respiration,
                                          pageTitle:
                                          TranslationBase.of(context).respirationRate,
                                          vitalList: mode.vitalSignResModelList,

                                        ),
                                      ),
                                    );
                                  }
                                } else if (index == 5) {
                                  if (isNotOneAppointment) {
                                    Navigator.push(
                                      context,
                                      FadePage(
                                        page: VitalSignItemDetailsScreen(
                                          pageKey: VitalSignDetails.BloodPressure,
                                          pageTitle: TranslationBase.of(context).bloodPressure,
                                          vitalList: mode.vitalSignResModelList,
                                        ),
                                      ),
                                    );
                                  }
                                }
                              },
                              child: VitalSignItem(
                                vitalSign: vitalSigns[index],
                              ),
                            );
                          },
                        ),
                      ),
                    ],
                  ),
                )
              : Center(
                  child: Texts('No Data'),
                ),
        );
      },
    );
  }

  Widget showMass(BuildContext context, String title, String weight, Color color, int f) {
    return Expanded(
      flex: 1,
      child: Container(
        height: double.infinity,
        width: double.infinity,
        child: Column(
          children: [
            Flexible(
              child: Row(
                children: [
                  mFlex(f),
                  Flexible(
                    flex: 10,
                    child: SvgPicture.asset(
                      "assets/images/new/mass/health_BMI.svg",
                      height: double.infinity,
                      width: double.infinity,
                      fit: BoxFit.fill,
                      color: color,
                    ),
                  ),
                  mFlex(f),
                ],
              ),
            ),
            mHeight(20),
            AutoSizeText(
              title,
              maxLines: 1,
              minFontSize: 6,
              style: TextStyle(
                color: color,
                fontSize: 10,
                letterSpacing: -0.6,
              ),
            ),
            AutoSizeText(
              weight,
              maxLines: 1,
              minFontSize: 6,
              style: TextStyle(
                color: color,
                fontSize: 10,
                letterSpacing: -0.6,
              ),
            )
          ],
        ),
      ),
    );
  }
}
