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/vital_sign/patient-vital-sign-history.dart';
import 'package:doctor_app_flutter/screens/patients/profile/vital_sign/LineChartCurvedBloodPressure.dart';
import 'package:doctor_app_flutter/screens/patients/profile/vital_sign/vital_sign_details_blood_pressurewideget.dart';
import 'package:doctor_app_flutter/utils/date-utils.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/material.dart';

import 'line_chart_curved_blood_pressure.dart';

class VitalSingChartBloodPressure extends StatelessWidget {
  VitalSingChartBloodPressure({
    Key? key,
    required this.vitalList,
    required this.name,
    required this.viewKey1,
    required this.viewKey2,
    required this.title1,
    required this.title2,
    required this.title3,
  }) : super(key: key);

  final List<VitalSignHistory> vitalList;
  final String name;
  final String viewKey1;
  final String viewKey2;
  final String title1;
  final String title2;
  final String title3;
  List<TimeSeriesSales2> timeSeriesData1 = [];
  List<TimeSeriesSales2> timeSeriesData2 = [];

  @override
  Widget build(BuildContext context) {
    generateData();
    return timeSeriesData1.length != 0 || timeSeriesData2.length != 0
        ? Padding(
            padding: const EdgeInsets.all(10.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 8),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(12)),
                  child: LineChartCurvedBloodPressureNew(
                    title: name,
                    isOX: title2 == "SAO2",
                    timeSeries1: timeSeriesData1,
                    timeSeries2: timeSeriesData2,
                    indexes: timeSeriesData1.length ~/ 5.5,
                  ),
                ),
                Container(
                  margin: EdgeInsets.symmetric(horizontal: 8, vertical: 16),
                  padding: EdgeInsets.only(top: 16, right: 18.0, left: 16.0),
                  decoration: BoxDecoration(
                      color: Colors.white,
                      borderRadius: BorderRadius.circular(12)),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      AppText(
                        TranslationBase.of(context).graphDetails,
                        fontSize: SizeConfig.textMultiplier! * 2.3,
                        fontWeight: FontWeight.bold,
                        fontFamily: 'Poppins',
                      ),
                      SizedBox(
                        height: 8,
                      ),
                      VitalSignBloodPressureWidget(
                        vitalList: vitalList,
                        title1: title1,
                        title2: title2,
                        title3: title3,
                        viewKey1: viewKey1,
                        viewKey2: viewKey2,
                      ),
                    ],
                  ),
                ),
                /*AppExpandableNotifier(
            // isExpand: true,
            headerWid: LineChartCurvedBloodPressure(
              title: name,
              timeSeries1: timeSeriesData1,
              timeSeries2: timeSeriesData2,
              indexes: timeSeriesData1.length ~/ 5.5,
            ),
            bodyWid: VitalSignBloodPressureWidget(
              vitalList: vitalList,
              title1: title1,
              title2: title2,
              title3: title3,
              viewKey1: viewKey1,
              viewKey2: viewKey2,
            ),
          ),*/
              ],
            ),
          )
        : Container(
            width: double.infinity,
            height: MediaQuery.of(context).size.height,
            child: Center(
              child: AppText(TranslationBase.of(context).vitalSignDetailEmpty),
            ),
          );
  }

  generateData() {
    if (vitalList.length > 0) {
      vitalList.reversed.toList().forEach(
        (element) {
          DateTime elementDate =
              AppDateUtils.getDateTimeFromServerFormat(element.createdOn);
          if (element.toJson()[viewKey1]?.toInt() != 0 &&
              element.toJson()[viewKey1]?.toInt() != null)
            timeSeriesData1.add(
              TimeSeriesSales2(
                new DateTime(
                    elementDate.year, elementDate.month, elementDate.day),
                element.toJson()[viewKey1]?.toDouble(),
              ),
            );
          if (element.toJson()[viewKey2]?.toInt() != 0 &&
              element.toJson()[viewKey2]?.toInt() != null)
            timeSeriesData2.add(
              TimeSeriesSales2(
                new DateTime(
                    elementDate.year, elementDate.month, elementDate.day),
                element.toJson()[viewKey2]?.toDouble(),
              ),
            );
        },
      );
    }
  }
}
