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/radiology/radiology_details_page.dart';
import 'package:doctor_app_flutter/screens/procedures/add_radiology_order.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/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_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';
import 'package:provider/provider.dart';

class RadiologyHomePage extends StatefulWidget {
  @override
  _RadiologyHomePageState createState() => _RadiologyHomePageState();
}

class _RadiologyHomePageState extends State<RadiologyHomePage> {
  String patientType;
  PatiantInformtion patient;
  String arrivalType;
  bool isInpatient;

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    final routeArgs = ModalRoute.of(context).settings.arguments as Map;
    patient = routeArgs['patient'];
    patientType = routeArgs['patientType'];
    arrivalType = routeArgs['arrivalType'];
    isInpatient = routeArgs['isInpatient'];
    print(arrivalType);
  }

  @override
  Widget build(BuildContext context) {
    return BaseView<ProcedureViewModel>(
      onModelReady: (model) => model.getPatientRadOrders(patient,
          patientType: patientType, isInPatient: false),
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        backgroundColor: Colors.grey[100],
        // appBarTitle: TranslationBase.of(context).radiology,
        appBar: PatientProfileHeaderNewDesignAppBar(
            patient, patient.patientType.toString() ?? '0', arrivalType),
        baseViewModel: model,
        body: FractionallySizedBox(
          widthFactor: 1.0,
          child: ListView(
            physics: BouncingScrollPhysics(),
            children: <Widget>[
              SizedBox(
                height: 12,
              ),
              if (model.radiologyList.isNotEmpty &&
                  patient.patientStatusType != 43)
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      AppText(
                        'Radiology',
                        style: "caption2",
                        color: Colors.black,
                        fontSize: 13,
                      ),
                      AppText(
                        'Result',
                        bold: true,
                        fontSize: 22,
                      ),
                    ],
                  ),
                ),
              if (patient.patientStatusType != null &&
                  patient.patientStatusType == 43)
                Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      AppText(
                        'Radiology',
                        style: "caption2",
                        color: Colors.black,
                        fontSize: 13,
                      ),
                      AppText(
                        'Result',
                        bold: true,
                        fontSize: 22,
                      ),
                    ],
                  ),
                ),
              if (patient.patientStatusType != null &&
                  patient.patientStatusType == 43)
                AddNewOrder(
                  onTap: () {
                    Navigator.push(
                      context,
                      MaterialPageRoute(
                          builder: (context) => AddSelectedRadiologyOrder(
                                patient: patient,
                                model: model,
                              )),
                    );
                  },
                  label: 'Apply for Radiology Order',
                ),
              ...List.generate(
                  model.radiologyList.length,
                  (index) => Container(
                        margin: EdgeInsets.all(10),
                        decoration: BoxDecoration(
                            border: Border.all(
                              width: 0.5,
                              color: Colors.white,
                            ),
                            borderRadius: BorderRadius.all(
                              Radius.circular(8.0),
                            ),
                            color: Colors.white),
                        child: Row(
                          children: [
                            Container(
                              width: 20,
                              height: 160,
                              decoration: BoxDecoration(
                                //Colors.red[900]  Color(0xff404545)
                                color: model.radiologyList[index].isLiveCareAppodynamicment
                                    ? Colors.red[900]
                                    : !model.radiologyList[index].isInOutPatient
                                    ? Colors.black
                                    : Color(0xffa9a089),
                                borderRadius: BorderRadius.only(
                                  topLeft: Radius.circular(8),
                                  bottomLeft: Radius.circular(8),

                                ),
                              ),
                              child: RotatedBox(
                                  quarterTurns: 3,
                                  child: Center(
                                    child: Text(
                                      model.radiologyList[index].isLiveCareAppodynamicment
                                          ? TranslationBase.of(context)
                                          .liveCare
                                          .toUpperCase()
                                          : !model.radiologyList[index].isInOutPatient
                                          ? TranslationBase.of(context)
                                          .inPatient
                                          .toUpperCase()
                                          : TranslationBase.of(context)
                                          .outpatient
                                          .toUpperCase(),
                                      style: TextStyle(color: Colors.white),
                                    ),
                                  )),
                            ),
                            Expanded(
                              child: DoctorCard(
                                isNoMargin: true,
                                doctorName: model.radiologyList[index].doctorName,
                                profileUrl: model.radiologyList[index].doctorImageURL,
                                invoiceNO: '${model.radiologyList[index].invoiceNo}',
                                branch: '${model.radiologyList[index].projectName}',
                                clinic: model.radiologyList[index].clinicDescription,
                                appointmentDate: !isInpatient
                                    ? model.radiologyList[index].orderDate
                                    : model.radiologyList[index].reportDate,
                                onTap: () {
                                  Navigator.push(
                                    context,
                                    FadePage(
                                      page: RadiologyDetailsPage(
                                        finalRadiology: model.radiologyList[index],
                                        patient: patient,
                                      ),
                                    ),
                                  );
                                },
                              ),
                            ),
                          ],
                        ),
                      )),
              if (model.radiologyList.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 Radiology Found'),
                      )
                    ],
                  ),
                )
            ],
          ),
        ),
      ),
    );
  }
}
