import 'package:diplomaticquarterapp/core/model/vital_sign/vital_sign_res_model.dart';
import 'package:diplomaticquarterapp/pages/medical/vital_sign/vital_sign_details_wideget.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.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';

class VitalSingChartAndDetials extends StatelessWidget {
  VitalSingChartAndDetials({
    Key key,
    @required this.vitalList,
    @required this.name,
    @required this.viewKey,
    @required this.title1,
    @required this.title2,
  }) : super(key: key);

  final List<VitalSignResModel> vitalList;
  final String name;
  final String viewKey;
  final String title1;
  final String title2;
  List<TimeSeriesSales2> timeSeriesData = [];

  @override
  Widget build(BuildContext context) {
   generateData();
    return Column(
      children: <Widget>[
        AppExpandableNotifier(
          isExpand: true,
          headerWidget: LineChartCurved(title: name,timeSeries:timeSeriesData,indexes: timeSeriesData.length~/5.5,),
          bodyWidget: VitalSignDetailsWidget(
            vitalList: vitalList,
            title1: title1,
            title2: title2,
            viewKey: viewKey,
          ),
        ),
      ],
    );
  }

  generateData() {
    if (vitalList.length > 0) {
      vitalList.reversed.toList().forEach(
            (element) {
              if( element.toJson()[viewKey]!=null && element.toJson()[viewKey]?.toInt()!=0)
          timeSeriesData.add(
            TimeSeriesSales2(
              new DateTime(element.vitalSignDate.year, element.vitalSignDate.month, element.vitalSignDate.day),
              element.toJson()[viewKey].toDouble(),
            ),
          );
        },
      );
    }
    return timeSeriesData.reversed.toList();
  }
}
