import 'package:doctor_app_flutter/core/model/labs/patient_lab_orders.dart';
import 'package:doctor_app_flutter/core/viewModel/labs_view_model.dart';
import 'package:doctor_app_flutter/models/patient/patiant_info_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient_profile_header_with_appointment_card_app_bar.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import 'laboratory_result_widget.dart';

class LaboratoryResultPage extends StatefulWidget {
  final PatientLabOrders patientLabOrders;
  final PatiantInformtion patient;
  final String patientType;
  final String arrivalType;

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

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

class _LaboratoryResultPageState extends State<LaboratoryResultPage> {
  @override
  Widget build(BuildContext context) {
    return BaseView<LabsViewModel>(
      onModelReady: (model) => model.getLaboratoryResult(
          invoiceNo: widget.patientLabOrders.invoiceNo,
          clinicID: widget.patientLabOrders.clinicID,
          projectID: widget.patientLabOrders.projectID,
          orderNo: widget.patientLabOrders.orderNo,
          patient: widget.patient,
          isInpatient: widget.patientType == "1"),
      builder: (_, model, w) => AppScaffold(
        isShowAppBar: true,
        appBar: PatientProfileHeaderWhitAppointmentAppBar(
          patient: widget.patient,
          patientType: widget.patientType ?? "0",
          arrivalType: widget.arrivalType ?? "0",
          orderNo: widget.patientLabOrders.orderNo,
          appointmentDate: widget.patientLabOrders.orderDate,
          doctorName: widget.patientLabOrders.doctorName,
          branch: widget.patientLabOrders.projectName,
          clinic: widget.patientLabOrders.clinicDescription,
          profileUrl: widget.patientLabOrders.doctorImageURL,
          invoiceNO: widget.patientLabOrders.invoiceNo,
        ),
        baseViewModel: model,
        body: Scaffold(
          body: SingleChildScrollView(
            child: Column(
              children: [
                ...List.generate(
                    model.patientLabSpecialResult.length,
                    (index) => LaboratoryResultWidget(
                          onTap: () async {},
                          billNo: widget.patientLabOrders.invoiceNo,
                          details: model
                              .patientLabSpecialResult[index].resultDataHTML,
                          orderNo: widget.patientLabOrders.orderNo,
                          patientLabOrder: widget.patientLabOrders,
                          patient: widget.patient,
                      isInpatient: widget.patientType == "1",
                        )),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
