import 'package:diplomaticquarterapp/core/model/vital_sign/vital_sign_res_model.dart';
import 'package:diplomaticquarterapp/pages/medical/vital_sign/vital_sign_details_blood_pressurewideget.dart';
import 'package:diplomaticquarterapp/pages/medical/vital_sign/vital_sign_details_wideget.dart';
import 'package:diplomaticquarterapp/widgets/charts/app_time_series_chart.dart';
import 'package:diplomaticquarterapp/widgets/others/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<VitalSignResModel> 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,
          headerWidget: LineChartCurvedBloodPressure(
            title: name,
            timeSeries1: timeSeriesData1,
            timeSeries2: timeSeriesData2,
            indexes: timeSeriesData1.length ~/ 5.5,
          ),
          bodyWidget: VitalSignBloodPressureWidget(
            vitalList: vitalList,
            title1: title1,
            title2: title2,
            title3: title3,
            viewKey1: viewKey1,
            viewKey2: viewKey2,
          ),
        ),
      ],
    );
  }

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