import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/model/charts/app_time_series_chart.dart';
import 'package:doctor_app_flutter/core/model/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/core/model/patient/vital_sign/patient-vital-sign-history.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/lookups/patient_lookup.dart';
import 'package:doctor_app_flutter/screens/patients/profile/vital_sign/vital_sign_detail_pain_scale.dart';
import 'package:doctor_app_flutter/screens/patients/profile/vital_sign/vital_sing_chart_and_detials.dart';
import 'package:doctor_app_flutter/screens/patients/profile/vital_sign/vital_sing_chart_blood_pressure.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/app_bar/patient-profile-app-bar.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class VitalSignItemDetailsScreen extends StatelessWidget {
  final vitalSignDetails pageKey;
  final String pageTitle;
  List<Map>? VSchart;
  PatiantInformtion patient;
  String? patientType;
  String? arrivalType;

  List<TimeSeriesSales2> timeSeriesData1 = [];
  List<TimeSeriesSales2> timeSeriesData2 = [];

  final String? viewKey1;
  final String? viewKey2;

  VitalSignItemDetailsScreen({required this.vitalList, required this.pageKey, this.viewKey1, this.viewKey2, required this.pageTitle, required this.patient, this.patientType, this.arrivalType});

  final List<VitalSignHistory> vitalList;

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    switch (pageKey) {
      case vitalSignDetails.BodyMeasurements:
        VSchart = [
          {
            'name': 'BMI',
            'nameAr': 'مؤشر الكتلة',
            'title1': 'Date',
            'title2': 'BMI',
            'title2Ar': 'الكتلة',
            'viewKey': 'BodyMassIndex',
          },
        ];

        break;

      case vitalSignDetails.Temperature:
        VSchart = [
          {
            'name': 'Temperature In Celsius',
            'nameAr': 'درجة الحرارة بالدرجة المئوية',
            'title1': 'Date',
            'title2': 'C',
            'title2Ar': 'ْس',
            'viewKey': 'TemperatureCelcius',
          },
        ];

        break;
      case vitalSignDetails.Pulse:
        VSchart = [
          {
            'name': 'Pulse Beat Per Minute',
            'nameAr': 'نبضة نبضة في الدقيقة',
            'title1': 'Date',
            'title2': 'Minute',
            'title2Ar': 'دقيقة',
            'viewKey': 'PulseBeatPerMinute',
          },
        ];

        break;
      case vitalSignDetails.Prescriptions:
        VSchart = [
          {
            'name': 'Respiration Beat Per Minute',
            'nameAr': 'ضربات التنفس في الدقيقة',
            'title1': 'Date',
            'title2': 'Beat Per Minute',
            'title2Ar': 'نفس في الدقيقة',
            'viewKey': 'RespirationBeatPerMinute',
          },
        ];

        break;
      case vitalSignDetails.BloodPressure:
        VSchart = [
          {
            'name': 'Blood Pressure Systolic Diastolic',
            'nameAr': 'ضغط الدم الإنقباض الإنبساط',
            'title1': 'Date',
            'title2': 'systolic',
            'title3': 'Diastolic',
            'title2Ar': 'الإنقباض',
            'title3Ar': 'الإنبساط',
            'viewKey': 'BloodPressure',
          },
        ];

        break;
      case vitalSignDetails.Respiration:
        VSchart = [
          {
            'name': 'Respiration Rate',
            'nameAr': 'معدل التنفس',
            'title1': 'Date',
            'title2': 'bpm',
            'title2Ar': 'نفس',
            'viewKey': 'RespirationBeatPerMinute',
          },
        ];

        break;
      case vitalSignDetails.heart:
        VSchart = [
          {
            'name': 'Heart rate',
            'nameAr': 'معدل النبض بالدقيقة',
            'title1': 'Date',
            'title2': 'bpm',
            'title2Ar': 'نبضة',
            'viewKey': 'PulseBeatPerMinute',
          },
        ];

        break;
      case vitalSignDetails.PainScale:
        VSchart = [
          {
            'name': 'PainScore',
            'nameAr': 'نقاط الألم',
            'title1': 'Date',
            'title2': 'Cm',
            'title2Ar': 'سم',
            'viewKey': 'PainScore',
          },
        ];

        break;
      case vitalSignDetails.Oxygenation:
        VSchart = [
          {
            'name': 'Oxygenation',
            'nameAr': 'الأوكسجين',
            'title1': 'Date',
            'title2': 'SAO2',
            'title3': 'FIO2',
            'title2Ar': 'SAO2',
            'title3Ar': 'FIO2',
            'viewKey': 'O2',
          },
        ];

        break;
      case vitalSignDetails.Weight:
        VSchart = [
          {
            'name': 'Weight Kg',
            'nameAr': 'الوزن كجم',
            'title1': 'Date',
            'title2': 'Kg',
            'title2Ar': 'كجم',
            'viewKey': 'WeightKg',
          },
        ];

        break;

      case vitalSignDetails.Height:
        VSchart = [
          {
            'name': 'Height Cm',
            'nameAr': 'الطول سم',
            'title1': 'Date',
            'title2': 'Cm',
            'title2Ar': 'سم',
            'viewKey': 'HeightCm',
          },
        ];

        break;
      default:
    }
    return AppScaffold(
      appBarTitle: pageTitle,
      backgroundColor: Color.fromRGBO(248, 248, 248, 1),
      isShowAppBar: true,
      appBar: PatientProfileAppBar(
        patient,
      ),
      body: SingleChildScrollView(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              margin: EdgeInsets.all(16.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  AppText(
                    "${patient.firstName ?? patient.patientDetails?.firstName ?? patient.fullName ?? ''}'s",
                    fontFamily: 'Poppins',
                    fontSize: SizeConfig.textMultiplier! * 1.6,
                    fontWeight: FontWeight.w600,
                  ),
                  AppText(
                    TranslationBase.of(context).vitalSign,
                    fontFamily: 'Poppins',
                    fontSize: SizeConfig.textMultiplier! * 3,
                    fontWeight: FontWeight.bold,
                  )
                ],
              ),
            ),
            Container(
              child: ListView(
                shrinkWrap: true,
                physics: NeverScrollableScrollPhysics(),
                children: VSchart!.map((chartInfo) {
                  var vitalListTemp = vitalList.where(
                    (element) => element.toJson()[chartInfo['viewKey']] != null,
                  );

                  if (chartInfo['viewKey'] == 'PainScore') {
                    return VitalSignDetailPainScale(vitalList);
                  }

                  if (vitalListTemp.length != 0 && chartInfo['viewKey'] == 'BloodPressure' || chartInfo['viewKey'] == 'O2') {
                    return VitalSingChartBloodPressure(
                      vitalList: vitalList,
                      name: projectViewModel.isArabic ? chartInfo['nameAr'] : chartInfo['name'],
                      title1: chartInfo['title1'],
                      title2: projectViewModel.isArabic ? chartInfo['title2Ar'] : chartInfo['title2'],
                      title3: projectViewModel.isArabic ? chartInfo['title3Ar'] : chartInfo['title3'],
                      viewKey1: chartInfo['viewKey'] == 'BloodPressure' ? 'BloodPressureHigher' : 'SAO2',
                      viewKey2: chartInfo['viewKey'] == 'BloodPressure' ? 'BloodPressureLower' : 'FIO2',
                    );
                  }

                  return vitalListTemp.length != 0
                      ? VitalSingChartAndDetials(
                          vitalList: vitalList,
                          name: projectViewModel.isArabic ? chartInfo['nameAr'] : chartInfo['name'],
                          title1: chartInfo['title1'],
                          title2: projectViewModel.isArabic ? chartInfo['title2Ar'] : chartInfo['title2'],
                          viewKey: chartInfo['viewKey'])
                      : Container();
                }).toList(),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
