import 'package:doctor_app_flutter/core/enum/filter_type.dart';
import 'package:doctor_app_flutter/core/viewModel/labs_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/procedure_View_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_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/screens/patients/profile/lab_result/laboratory_result_page.dart';
import 'package:doctor_app_flutter/screens/procedures/add_lab_orders.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/add-order/addNewOrder.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-profile-header-new-design-app-bar.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-profile-header-new-design.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_expandable_notifier_new.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/doctor_card.dart';
import 'package:doctor_app_flutter/widgets/transitions/fade_page.dart';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class LabsHomePage extends StatelessWidget {
  String patientType;
  String arrivalType;
  @override
  Widget build(BuildContext context) {
    final routeArgs = ModalRoute.of(context).settings.arguments as Map;

    PatiantInformtion patient = routeArgs['patient'];
    patientType = routeArgs['patientType'];
    arrivalType = routeArgs['arrivalType'];
    print(arrivalType);
    return BaseView<ProcedureViewModel>(
      onModelReady: (model) => model.getLabs(patient,isArrived: (patientType != null && patientType == '7' && patient.patientStatusType == 43)),
      builder: (context, ProcedureViewModel model, widget) => AppScaffold(
        baseViewModel: model,
        backgroundColor: Colors.grey[100],
        isShowAppBar: true,
        appBar: PatientProfileHeaderNewDesignAppBar(
            patient, patient.patientType.toString() ?? '0', patientType),
        body: SingleChildScrollView(
          physics: BouncingScrollPhysics(),
          child: FractionallySizedBox(
            widthFactor: 1.0,
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: <Widget>[
                SizedBox(
                  height: 12,
                ),
                if(model.patientLabOrdersList.isNotEmpty && patient.patientStatusType != 43)
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      AppText(
                        'Lab',
                        style: "caption2",
                        color: Colors.black,
                        fontSize: 13,
                      ),
                      AppText(
                        'Result',
                        bold: true,
                        fontSize: 22,
                      ),
                    ],
                  ),
                ),
                if(patient.patientStatusType == 43)
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        AppText(
                          'Lab',
                          style: "caption2",
                          color: Colors.black,
                          fontSize: 13,
                        ),
                        AppText(
                          'Result',
                          bold: true,
                          fontSize: 22,
                        ),
                      ],
                    ),
                  ),
                if (patientType != null && patientType == '7' && patient.patientStatusType == 43)
                AddNewOrder( onTap: () {
                  Navigator.push(
                    context,
                    MaterialPageRoute(
                        builder: (context) => AddSelectedLabOrder(
                          patient: patient,
                          model: model,
                        )),
                  );
                },label: 'Apply for New Lab Order',),
                ...List.generate(
                  model.patientLabOrdersList.length,
                  (index) => Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: model
                        .patientLabOrdersList[index].patientLabOrdersList
                        .map((labOrder) {
                      return DoctorCard(
                        onTap: () => Navigator.push(
                          context,
                          FadePage(
                            page: LaboratoryResultPage(
                              patientLabOrders: labOrder,
                              patient: patient,
                              arrivalType: arrivalType,
                              patientType: patientType,
                            ),
                          ),
                        ),
                        doctorName: labOrder.doctorName,
                        invoiceNO: ' ${labOrder.invoiceNo}',
                        profileUrl: labOrder.doctorImageURL,
                        branch: labOrder.projectName,
                        clinic: labOrder.clinicDescription,
                        appointmentDate: labOrder.orderDate,
                        orderNo: labOrder.orderNo,
                      );
                    }).toList(),
                  ),
                ),
                if(model.patientLabOrdersList.isEmpty && patient.patientStatusType != 43)
                  Center(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        SizedBox(height: 100,),
                        Image.asset('assets/images/no-data.png'),
                        Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: AppText('No Lab Result Found'),
                        )

                      ],
                    ),
                  )
              ],
            ),
          ),
        ),
      ),
    );
  }
}
