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

class LabResultDetailsWidget extends StatefulWidget {
  final List<LabOrderResult> labResult;

  LabResultDetailsWidget({
    required this.labResult,
  });

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

class _VitalSignDetailsWidgetState extends State<LabResultDetailsWidget> {
  @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,
                        fontFamily: 'Poppins',
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child: Container(
                    padding: EdgeInsets.all(8),
                    child: Container(
                      child: AppText(
                        TranslationBase.of(context).labResult,
                        fontSize: SizeConfig.textMultiplier! * 1.6,
                        fontWeight: FontWeight.bold,
                        fontFamily: 'Poppins',
                      ),
                      // 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.labResult.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,
              fontFamily: 'Poppins',
            ),
          ),
        ),
        Container(
          child: Container(
            padding: EdgeInsets.all(8),
            color: Colors.white,
            child: AppText(
              '${vital.resultValue}',
              fontSize: SizeConfig.textMultiplier! * 1.8,
              fontWeight: FontWeight.w600,
              fontFamily: 'Poppins',
            ),
          ),
        ),
      ]));
    });
    return tableRow;
  }
}
