import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/model/labs/lab_result_history.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.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/material.dart';
import 'package:provider/provider.dart';

class LabResultHistoryDetailsWidget extends StatefulWidget {
  final List<LabResultHistory> labResultHistory;

  LabResultHistoryDetailsWidget({
    required this.labResultHistory,
  });

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

class _VitalSignDetailsWidgetState extends State<LabResultHistoryDetailsWidget> {
  @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.6,
                        fontWeight: FontWeight.bold,
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child: Container(
                    padding: EdgeInsets.all(8),
                    child: Container(
                      child: AppText(
                        TranslationBase.of(context).labResult,
                        fontSize: SizeConfig.textMultiplier! * 1.6,
                        fontWeight: FontWeight.bold,
                      ),
                      // height: 60
                    ),
                  ),
                )
              ],
            ),
            const Divider(
              height: 1,
              thickness: 1,
              color: Colors.black,
            ),
            Table(
              border: TableBorder.symmetric(
                inside: BorderSide(width: 1.0, color: Colors.grey[300]!),
              ),
              children: fullData(projectViewModel),
            ),
          ],
        ),
      ),
    );
  }

  List<TableRow> fullData(ProjectViewModel projectViewModel) {
    List<TableRow> tableRow = [];
    widget.labResultHistory.forEach(
      (vital) {
        var date = AppDateUtils.convertStringToDate(vital.verifiedOnDateTime!);
        tableRow.add(
          TableRow(
            children: [
              Container(
                child: Container(
                  padding: EdgeInsets.all(8),
                  color: Colors.white,
                  child: AppText(
                    '${projectViewModel.isArabic ? AppDateUtils.getWeekDayArabic(date.weekday) : AppDateUtils.getWeekDay(date.weekday)} ,${date.day} ${projectViewModel.isArabic ? AppDateUtils.getMonthArabic(date.month) : AppDateUtils.getMonth(date.month)} ${date.year}',
                    fontSize: SizeConfig.textMultiplier! * 1.8,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ),
              Container(
                child: Container(
                  padding: EdgeInsets.all(8),
                  color: Colors.white,
                  child: AppText(
                    '${vital.resultValue}',
                    fontSize: SizeConfig.textMultiplier! * 1.8,
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
    return tableRow;
  }
}
