import 'package:doctor_app_flutter/core/viewModel/medical_file_view_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.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/medical-file/medical_file_details.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/profile/patient-page-header-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/network_base_view.dart';
import 'package:flutter/material.dart';

class MedicalFilePage extends StatefulWidget {
  @override
  _MedicalFilePageState createState() => _MedicalFilePageState();
}

class _MedicalFilePageState extends State<MedicalFilePage> {
  PatiantInformtion patient;
  @override
  Widget build(BuildContext context) {
    final routeArgs = ModalRoute.of(context).settings.arguments as Map;
    patient = routeArgs['patient'];
    return BaseView<MedicalFileViewModel>(
      onModelReady: (model) => model.getMedicalFile(mrn: patient.patientId),
      builder:
          (BuildContext context, MedicalFileViewModel model, Widget child) =>
              AppScaffold(
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).medicalReport.toUpperCase(),
        body: NetworkBaseView(
          baseViewModel: model,
          child: SingleChildScrollView(
            child: Container(
              color: Colors.white,
              child: Column(
                // mainAxisAlignment: model.medicalFileList.length != 0 &&
                //         model.medicalFileList != null
                //     ? MainAxisAlignment.start
                //     : MainAxisAlignment.center,
                children: [
                  PatientPageHeaderWidget(patient),
                  Divider(
                    height: 1.0,
                    thickness: 1.0,
                    color: Colors.grey,
                  ),
                  (model.medicalFileList != null &&
                          model.medicalFileList.length != 0)
                      ? ListView.builder(
                          //physics: ,
                          physics: NeverScrollableScrollPhysics(),
                          scrollDirection: Axis.vertical,
                          shrinkWrap: true,
                          itemCount: model.medicalFileList[0].entityList[0]
                              .timelines.length,
                          itemBuilder: (BuildContext ctxt, int index) {
                            return Padding(
                              padding: EdgeInsets.symmetric(
                                  horizontal: 12.0, vertical: 8.0),
                              child: InkWell(
                                child: Container(
                                  child: Column(
                                    children: [
                                      Row(
                                        children: [
                                          AppText(
                                            TranslationBase.of(context).branch +
                                                ": ",
                                            fontWeight: FontWeight.w700,
                                          ),
                                          AppText(model
                                              .medicalFileList[0]
                                              .entityList[0]
                                              .timelines[index]
                                              .projectName),
                                        ],
                                      ),
                                      Row(
                                        children: [
                                          AppText(
                                            TranslationBase.of(context)
                                                    .doctorName
                                                    .toUpperCase() +
                                                ": ",
                                            fontWeight: FontWeight.w700,
                                          ),
                                          Expanded(
                                            child: AppText(
                                              model
                                                  .medicalFileList[0]
                                                  .entityList[0]
                                                  .timelines[index]
                                                  .doctorName,
                                              fontWeight: FontWeight.w700,
                                            ),
                                          ),
                                        ],
                                      ),
                                      Row(
                                        children: [
                                          AppText(
                                            TranslationBase.of(context)
                                                    .clinicName +
                                                ": ",
                                            fontWeight: FontWeight.w700,
                                          ),
                                          AppText(
                                            model
                                                .medicalFileList[0]
                                                .entityList[0]
                                                .timelines[index]
                                                .clinicName,
                                          ),
                                        ],
                                      ),
                                      SizedBox(height: 10.0),
                                      Divider(
                                        height: 1.0,
                                        thickness: 1.0,
                                        color: Colors.grey.shade400,
                                      )
                                    ],
                                  ),
                                ),
                                onTap: () {
                                  Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) =>
                                            MedicalFileDetails(
                                              age: patient.age,
                                              firstName: patient.firstName,
                                              lastName: patient.lastName,
                                              gender: patient.genderDescription,
                                              encounterNumber: index,
                                              pp: patient.patientId,
                                            )),
                                  );
                                },
                              ),
                            );
                          })
                      : Container(
                          child: AppText(
                            'THERES NO MEDICAL FILE FOR THIS Patient',
                          ),
                        )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
