import 'package:diplomaticquarterapp/core/model/my_trakers/blood_sugar/DiabtecPatientResult.dart';
import 'package:diplomaticquarterapp/core/model/my_trakers/chartData/WeekChartDate.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.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:charts_flutter/flutter.dart' as charts;
import 'package:hexcolor/hexcolor.dart';

class BloodSugarWeeklyPage extends StatelessWidget {
  final List<charts.Series<WeekChartDate, DateTime>> data;
  final List<DiabtecPatientResult> diabtecPatientResult;

  const BloodSugarWeeklyPage({Key key, this.data, this.diabtecPatientResult})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      body: ListView(
        children: [
          Container(
            width: double.maxFinite,
            height: 180,
            color: Colors.white,
            child: charts.TimeSeriesChart(
              data,
              dateTimeFactory: const charts.LocalDateTimeFactory(),
            ),
          ),
          SizedBox(height: 12,),

          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Texts('Details'),
          ),
          Container(
            padding: EdgeInsets.all(10),
            color: Colors.transparent,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                Table(
                  border: TableBorder.symmetric(
                    inside: BorderSide(width: 2.0, color: Colors.grey[300]),
                  ),
                  children: fullData(),
                ),
              ],
            ),
          )
        ],
      ),
    );
  }

  List<TableRow> fullData() {
    List<TableRow> tableRow = [];
    tableRow.add(
      TableRow(
        children: [
          Container(
            child: Container(
              decoration: BoxDecoration(
                color: Hexcolor('#515B5D'),
                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: Hexcolor('#515B5D'),
                ),
                child: Center(
                  child: Texts('Time', color: Colors.white,fontSize: 15,),
                ),
                height: 40),
          ),
          Container(
            child: Container(
                decoration: BoxDecoration(
                  color: Hexcolor('#515B5D'),
                ),
                child: Center(
                  child: Texts('Measured', color: Colors.white,fontSize: 15,),
                ),
                height: 40),
          ),
          Container(
            child: Container(
                decoration: BoxDecoration(
                  color: Hexcolor('#515B5D'),
                ),
                child: Center(
                  child: Texts('Value', color: Colors.white,fontSize: 15,),
                ),
                height: 40),
          ),
          Container(
            child: Container(
                decoration: BoxDecoration(
                  color: Hexcolor('#515B5D'),
                  borderRadius: BorderRadius.only(
                    topRight: Radius.circular(10.0),
                  ),
                ),
                child: Center(
                  child: Texts('Edit', color: Colors.white,fontSize: 15,),
                ),
                height: 40),
          ),
        ],
      ),
    );
    diabtecPatientResult.forEach((diabtec) {
        tableRow.add(
          TableRow(
            children: [
              Container(
                child: Container(
                  height: 70,
                  padding: EdgeInsets.all(10),
                  color: Colors.white,
                  child: Center(
                    child: Texts(
                      '${DateUtil.getMonthDayYearDateFormatted(diabtec.dateChart)}',
                      textAlign: TextAlign.center,
                      fontSize: 12,
                    ),
                  ),
                ),
              ),
              Container(
                child: Container(
                  height: 70,
                  padding: EdgeInsets.all(10),
                  color: Colors.white,
                  child: Center(
                    child: Texts(
                      '${diabtec.dateChart.hour}:${diabtec.dateChart.minute}',
                      textAlign: TextAlign.center,
                      fontSize: 12,
                    ),
                  ),
                ),
              ),
              Container(
                child: Container(
                  height: 70,
                  padding: EdgeInsets.all(10),
                  color: Colors.white,
                  child: Center(
                    child: Texts(
                      '${diabtec.measuredDesc}',
                      textAlign: TextAlign.center,
                      fontSize: 12,
                    ),
                  ),
                ),
              ),
              Container(
                child: Container(
                  height: 70,
                  padding: EdgeInsets.all(10),
                  color: Colors.white,
                  child: Center(
                    child: Texts(
                      '${diabtec.resultValue}',
                      textAlign: TextAlign.center,
                      fontSize: 12,
                    ),
                  ),
                ),
              ),
              Container(
                child: Container(
                  height: 70,
                  padding: EdgeInsets.all(10),
                  color: Colors.white,
                  child: Center(
                    child: Icon(Icons.edit),
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
    return tableRow;
  }
}
