import 'package:diplomaticquarterapp/core/model/labs/patient_lab_orders.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/labs_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/medical/LabResult/laboratory_result_widget.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class LaboratoryResultPage extends StatefulWidget {
  final PatientLabOrders patientLabOrders;

  LaboratoryResultPage({Key key, this.patientLabOrders});

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

class _LaboratoryResultPageState extends State<LaboratoryResultPage> {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<LabsViewModel>(
      onModelReady: (model) => model.getLaboratoryResult(
          invoiceNo: widget.patientLabOrders.invoiceNo,
          clinicID: widget.patientLabOrders.clinicID,
          projectID: widget.patientLabOrders.projectID,
          orderNo: widget.patientLabOrders.orderNo,
          setupID: widget.patientLabOrders.setupID),
      builder: (_, model, w) => AppScaffold(
        isShowAppBar: true,
        appBarTitle: widget.patientLabOrders.doctorName,
        baseViewModel: model,
        showNewAppBar: true,
        showNewAppBarTitle: true,
        backgroundColor: Color(0xffF8F8F8),
        body: ListView.builder(
          physics: BouncingScrollPhysics(),
          padding: EdgeInsets.only(bottom: 12),
          itemBuilder: (context, index) => LaboratoryResultWidget(
            onTap: () async {
              GifLoaderDialogUtils.showMyDialog(context);
              await model.sendLabReportEmail(patientLabOrder: widget.patientLabOrders, mes: TranslationBase.of(context).sendSuc, userObj: projectViewModel.user);
              GifLoaderDialogUtils.hideDialog(context);
            },
            billNo: widget.patientLabOrders.invoiceNo,
            details: model.patientLabSpecialResult[index].resultDataHTML,
            orderNo: widget.patientLabOrders.orderNo,
            patientLabOrder: widget.patientLabOrders,
          ),
          itemCount: model.patientLabSpecialResult.length,
        ),
      ),
    );
  }
}
