import 'package:hmg_patient_app/core/model/labs/LabOrderResult.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/uitl/date_uitl.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils.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({
    this.labResult,
  });

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

class _VitalSignDetailsWidgetState extends State<LabResultDetailsWidget> {

  late ProjectViewModel projectViewModel;

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of(context);
    return Table(
      columnWidths: {
        0: FlexColumnWidth(2),
        1: FlexColumnWidth(1),
      },
      children: fullData(widget.labResult!, context),
    );
  }

  List<TableRow> fullData(List<LabOrderResult> labOrderResultList, context) {
    List<TableRow> tableRow = [];
    tableRow.add(
      TableRow(
        children: [
          Utils.tableColumnTitle(TranslationBase.of(context).date),
          Utils.tableColumnTitle(TranslationBase.of(context).labResults),
        ],
      ),
    );

    for (int i = 0; i < labOrderResultList.length; i++)
      tableRow.add(
        TableRow(
          children: [
            Utils.tableColumnValue(DateUtil.getDayMonthYearDateFormatted(DateUtil.convertStringToDate(labOrderResultList![i].verifiedOnDateTime!)), isLast: i == (labOrderResultList.length - 1), mProjectViewModel: projectViewModel),
            Utils.tableColumnValue(labOrderResultList[i].resultValue!, isLast: i == (labOrderResultList.length - 1), mProjectViewModel: projectViewModel),
          ],
        ),
      );
    return tableRow;
  }
}
