import 'package:doctor_app_flutter/models/patient/vital_sign/patient-vital-sign-data.dart';
import 'package:doctor_app_flutter/models/patient/vital_sign/patient-vital-sign-history.dart';
import 'package:doctor_app_flutter/screens/patients/profile/vital_sign/vital_sign_details_blood_pressurewideget.dart';
import 'package:doctor_app_flutter/util/date-utils.dart';
import 'package:doctor_app_flutter/widgets/charts/app_time_series_chart.dart';
import 'package:doctor_app_flutter/widgets/shared/app_expandable_notifier.dart';
import 'package:flutter/material.dart';

import 'package:charts_flutter/flutter.dart' as charts;

import 'LineChartCurved.dart';
import 'LineChartCurvedBloodPressure.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 Column(
      children: <Widget>[
        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,
          ),
        ),
      ],
    );
  }

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