import 'package:diplomaticquarterapp/core/viewModels/medical/blood_pressure_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/medical/my_trackers/widget/MonthCurvedChartBloodPressure.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/charts/app_time_series_chart.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';

class BloodPressureMonthlyPage extends StatelessWidget {
  final BloodPressureViewMode model;

  const BloodPressureMonthlyPage({Key key, this.model}) : super(key: key);


  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);

    return AppScaffold(
      body: ListView(
        children: [
            Container(
              margin: EdgeInsets.only(top: 12, left: 8, right: 8),
              color: Colors.white,
              child: MonthCurvedChartBloodPressure(
                horizontalInterval: 20.0,
                title: TranslationBase.of(context).bloodPressure,
                timeSeries1: model.weighMonthTimeSeriesDataTop.isEmpty?[TimeSeriesSales3(0,0.0)]:model.weighMonthTimeSeriesDataTop,
                timeSeries2: model.weighMonthTimeSeriesDataLow.isEmpty?[TimeSeriesSales3(0,0.0)]:model.weighMonthTimeSeriesDataLow,
                indexes: model.weightWeekTimeSeriesDataLow.length ~/ 5.5,
              ),
            ),
          SizedBox(
            height: 12,
          ),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Texts(TranslationBase.of(context).details),
          ),
          Container(
            padding: EdgeInsets.all(10),
            color: Colors.transparent,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                model.weighMonthTimeSeriesDataTop.isEmpty? Container(child: Center(child: Texts(TranslationBase.of(context).noDataAvailable),),):Table(
                  border: TableBorder.symmetric(
                    inside: BorderSide(width: 2.0, color: Colors.grey[300]),
                  ),
                  children: fullData(context,projectViewModel,model),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

  List<TableRow> fullData(BuildContext context,
      ProjectViewModel projectViewModel, BloodPressureViewMode model) {
    List<TableRow> tableRow = [];
    tableRow.add(
      TableRow(
        children: [
          Container(
            child: Container(
              decoration: BoxDecoration(
                color: Theme.of(context).primaryColor,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(10.0),
                ),
              ),
              child: Center(
                child: Texts(
                  'Date',
                  color: Colors.white,
                  fontSize: 15,
                ),
              ),
              height: 40,
            ),
          ),
          Container(
            child: Container(
                decoration: BoxDecoration(
                  color: Theme.of(context).primaryColor,
                ),
                child: Center(
                  child: Texts(
                    'Time',
                    color: Colors.white,
                    fontSize: 15,
                  ),
                ),
                height: 40),
          ),
          Container(
            child: Container(
                decoration: BoxDecoration(
                  color: Theme.of(context).primaryColor,
                ),
                child: Center(
                  child: Texts(
                    'Arm',
                    color: Colors.white,
                    fontSize: 15,
                  ),
                ),
                height: 40),
          ),
          Container(
            child: Container(
                decoration: BoxDecoration(
                  color: Theme.of(context).primaryColor,
                  borderRadius: BorderRadius.only(
                    topRight: Radius.circular(10.0),
                  ),
                ),
                child: Center(
                  child: Texts(
                    'SBP/DBP',
                    color: Colors.white,
                    fontSize: 15,
                  ),
                ),
                height: 40),
          ),
        ],
      ),
    );
    model.monthDiabtecPatientResult.reversed.forEach(
      (diabtec) {
        tableRow.add(
          TableRow(
            children: [
              Container(
                color: Colors.white,
                child: Center(
                  child: Texts(
                    '${projectViewModel.isArabic? DateUtil.getMonthDayYearDateFormattedAr(diabtec.bloodPressureDate):DateUtil.getMonthDayYearDateFormatted(diabtec.bloodPressureDate)}',
                    fontSize: 15,
                    textAlign: TextAlign.center,
                  ),
                ),
                height: 40,
              ),
              Container(
                  color: Colors.white,
                  child: Center(
                    child: Texts(
                      '${diabtec.bloodPressureDate.hour}:${diabtec.bloodPressureDate.minute}',
                      fontSize: 15,
                    ),
                  ),
                  height: 40),
              Container(
                  color: Colors.white,
                  child: Center(
                    child: Texts(
                      diabtec.measuredArmDesc,
                      fontSize: 15,
                    ),
                  ),
                  height: 40),
              Container(
                  color: Colors.white,
                  child: Center(
                    child: Texts(
                      '${diabtec.systolicePressure}/${diabtec.diastolicPressure}',
                      color: Colors.red,
                      fontSize: 15,
                    ),
                  ),
                  height: 40),
            ],
          ),
        );
      },
    );
    return tableRow;
  }
}
