import 'package:doctor_app_flutter/core/enum/master_lookup_key.dart';
import 'package:doctor_app_flutter/core/viewModel/SOAP_view_model.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/icons_app/doctor_app_icons.dart';
import 'package:doctor_app_flutter/models/SOAP/GeneralGetReqForSOAP.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/patient_profile_screen.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.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';
import 'package:provider/provider.dart';

class PatientPageHeaderWidget extends StatelessWidget {

  final PatiantInformtion patient;
  PatientPageHeaderWidget(this.patient);

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);

    return BaseView<SOAPViewModel>(
        onModelReady: (model) async {
          GeneralGetReqForSOAP generalGetReqForSOAP = GeneralGetReqForSOAP(
              patientMRN: patient.patientMRN??patient.patientId,
              doctorID: '',
              editedBy: '');
          await model.getPatientAllergy(generalGetReqForSOAP);
          if (model.allergiesList.length == 0) {
            await model.getMasterLookup(MasterKeysService.Allergies);
          }
          if (model.allergySeverityList.length == 0) {
            await model.getMasterLookup(MasterKeysService.AllergySeverity);
          }

        },
        builder: (_, model, w) => Container(
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  Padding(
                    padding: const EdgeInsets.all(8.0),
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        AvatarWidget(
                          Icon(
                            patient.genderDescription == "Male"
                                ? DoctorApp.male
                                : DoctorApp.female_icon,
                            size: 70,
                            color: Colors.white,
                          ),
                        ),
                        SizedBox(
                          width: 20,
                        ),
                        Expanded(
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: [
                              SizedBox(
                                height: 5,
                              ),
                              AppText(
                                patient.firstName + '  ' + patient.lastName,
                                color: Colors.black,
                                fontWeight: FontWeight.bold,
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  AppText(
                                    TranslationBase.of(context).age ,
                                    color: Colors.black,
                                    fontWeight: FontWeight.bold,
                                  ),
                                  SizedBox(
                                    width: 20,
                                  ),
                                  AppText(
                                    patient.age.toString(),
                                    color: Colors.black,
                                    fontWeight: FontWeight.normal,
                                  ),
                                ],
                              ),
                              model.patientAllergiesList.isNotEmpty && model.getAllergicNames(projectViewModel.isArabic)!='' ?AppText(
                                TranslationBase.of(context).allergicTO +" : "+model.getAllergicNames(projectViewModel.isArabic),
                                color: Color(0xFFB9382C),
                                fontWeight: FontWeight.bold,
                              ) : AppText(''),
                            ],
                          ),
                        )
                      ],
                    ),
                  ),
                  Container(
                    width: double.infinity,
                    height: 1,
                    color: Color(0xffCCCCCC),
                  ),
                  SizedBox(
                    width: 20,
                  ),
                ],
              ),
            ));
  }
}
