import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/models/patient/lab_orders/lab_orders_res_model.dart';
import 'package:doctor_app_flutter/providers/patients_provider.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/widgets/doctor/lab_result_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/card_with_bgNew_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/dr_app_circular_progress_Indeicator.dart';
import 'package:doctor_app_flutter/widgets/shared/errors/dr_app_embedded_error.dart';
import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';

class LabResult extends StatefulWidget {
  final LabOrdersResModel labOrders;

  LabResult({Key key, this.labOrders});

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

class _LabResultState extends State<LabResult> {
  PatientsProvider patientsProv;
  bool _isInit = true;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    if (_isInit) {
      patientsProv = Provider.of<PatientsProvider>(context);
      patientsProv.getLabResult(widget.labOrders);
      // getLabResultOrders(context);
    }
    _isInit = false;
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      appBarTitle: TranslationBase.of(context).labOrders,
      body: patientsProv.isLoading
          ? DrAppCircularProgressIndeicator()
          : patientsProv.isError
              ? DrAppEmbeddedError(error: patientsProv.error)
              : patientsProv.labResultList.length == 0
                  ? DrAppEmbeddedError(
                      error: TranslationBase.of(context).errorNoLabOrders)
                  : Container(
                      margin: EdgeInsets.fromLTRB(
                          SizeConfig.realScreenWidth * 0.05,
                          0,
                          SizeConfig.realScreenWidth * 0.05,
                          0),
                      child: ListView(
                        children: <Widget>[
                          CardWithBgWidgetNew(
                            widget: Row(
                              mainAxisAlignment: MainAxisAlignment.start,
                              children: <Widget>[
                                AppText(
                                  TranslationBase.of(context).invoiceNo,
                                  fontSize: 2 * SizeConfig.textMultiplier,
                                  color: Colors.grey[800],
                                ),
                                AppText(
                                  ' ${widget.labOrders.invoiceNo}',
                                  fontSize: 2 * SizeConfig.textMultiplier,
                                  color: Colors.grey[800],
                                ),
                              ],
                            ),
                          ),
                          CardWithBgWidgetNew(
                              widget: LabResultWidget(
                            labResult: patientsProv.labResultList,
                          ))
                        ],
                      ),
                    ),
    );
  }
}
