import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/model/diabetic_chart/GetDiabeticChartValuesResponseModel.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/core/model/patient/vital_sign/patient-vital-sign-history.dart';
import 'package:doctor_app_flutter/utils/date-utils.dart';
import 'package:doctor_app_flutter/utils/translations_delegate_base_utils.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class DiabeticDetails extends StatefulWidget {
  final List<GetDiabeticChartValuesResponseModel>? diabeticDetailsList;

  DiabeticDetails({
    Key? key,
    this.diabeticDetailsList,
  });

  @override
  _VitalSignDetailsWidgetState createState() => _VitalSignDetailsWidgetState();
}

class _VitalSignDetailsWidgetState extends State<DiabeticDetails> {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return Container(
      margin: EdgeInsets.all(0),
      child: Container(
        color: Colors.transparent,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Row(
              children: [
                Expanded(
                  child: Container(
                    child: Container(
                      padding: EdgeInsets.all(8),
                      child: AppText(
                        TranslationBase.of(context).date,
                        fontSize: SizeConfig.textMultiplier! * 1.5,
                        fontWeight: FontWeight.bold,
                        fontFamily: 'Poppins',
                      ),
                      // height: 60,
                    ),
                  ),
                ),
                Expanded(
                  child: Container(
                    padding: EdgeInsets.all(8),
                    child: Container(
                      child: AppText(
                        "Result",
                        fontSize: SizeConfig.textMultiplier! * 1.5,
                        fontWeight: FontWeight.bold,
                        fontFamily: 'Poppins',
                      ),
                      // height: 60
                    ),
                  ),
                ),
              ],
            ),
            const Divider(
              height: 1,
              thickness: 1,
              color: Colors.black,
            ),
            Table(
              border: TableBorder(
                horizontalInside:
                    BorderSide(width: 1.0, color: Colors.grey[300]!),
              ),
              children: fullData(projectViewModel),
            ),
          ],
        ),
      ),
    );
  }

  List<TableRow> fullData(ProjectViewModel projectViewModel) {
    List<TableRow> tableRow = [];
    widget.diabeticDetailsList!.forEach((diabetic) {
      var data = diabetic.resultValue;
      //https://cloudsolutions-sa.atlassian.net/browse/V4-39217?focusedCommentId=47028722
      DateTime elementDate =
          AppDateUtils.parseDateTimeWithRiyadhTZ(diabetic.dateChart!);
      if (data != 0)
        tableRow.add(TableRow(children: [
          Container(
            child: Container(
              padding: EdgeInsets.all(10),
              color: Colors.white,
              child: AppText(
                '${projectViewModel.isArabic ? AppDateUtils.getWeekDayArabic(elementDate.weekday) : AppDateUtils.getWeekDay(elementDate.weekday)}, ${elementDate.day} ${projectViewModel.isArabic ? AppDateUtils.getMonthArabic(elementDate.month) : AppDateUtils.getMonth(elementDate.month)}, ${elementDate.year} ${AppDateUtils.getHour(elementDate)}',
                // textAlign: TextAlign.center,
                fontSize: SizeConfig.textMultiplier! * 1.6,
                fontWeight: FontWeight.w600,

                fontFamily: 'Poppins',
              ),
            ),
          ),
          Container(
            child: Container(
              padding: EdgeInsets.all(10),
              color: Colors.white,
              child: AppText(
                '${diabetic.resultValue}',
                // textAlign: TextAlign.center,
                fontSize: SizeConfig.textMultiplier! * 1.6,
                fontWeight: FontWeight.w600,

                fontFamily: 'Poppins',
              ),
            ),
          ),
        ]));
    });
    return tableRow;
  }
}
