import 'package:doctor_app_flutter/core/viewModel/patient-referral-viewmodel.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/screens/patients/profile/referral/referred_patient_detail_in-paint.dart';
import 'package:doctor_app_flutter/util/date-utils.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/patients/patient-referral-item-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/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

class ReferredPatientScreen extends StatelessWidget {
  // previous design page is: MyReferredPatient
  @override
  Widget build(BuildContext context) {
    return BaseView<PatientReferralViewModel>(
      onModelReady: (model) => model.getMyReferredPatient(),
      builder: (_, model, w) => AppScaffold(
        baseViewModel: model,
        isShowAppBar: false,
        appBarTitle: TranslationBase.of(context).referredPatient,
        body: model.listMyReferredPatientModel == null ||
                model.listMyReferredPatientModel.length == 0
            ? Center(
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Container(
                      height: 100,
                    ),
                    Image.asset('assets/images/no-data.png'),
                    Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: AppText(
                        TranslationBase.of(context).referralEmptyMsg,
                        color: Theme.of(context).errorColor,
                      ),
                    )
                  ],
                ),
              )
            : SingleChildScrollView(
                // DoctorApplication.svc/REST/GtMyReferredPatient
                child: Container(
                  margin: EdgeInsets.only(top: 70),
                  child: Column(
                    children: [
                      // const Divider(
                      //   color: Color(0xffCCCCCC),
                      //   height: 1,
                      //   thickness: 2,
                      //   indent: 0,
                      //   endIndent: 0,
                      // ),
                      ...List.generate(
                        model.listMyReferredPatientModel.length,
                        (index) => InkWell(
                          onTap: () {
                            Navigator.push(
                              context,
                              FadePage(
                                page: ReferredPatientDetailScreen(
                                    model.getReferredPatientItem(index)),
                              ),
                            );
                          },
                          child: PatientReferralItemWidget(
                            referralStatus:model.getReferredPatientItem(index).referralStatusDesc,
                            referralStatusCode: model
                                .getReferredPatientItem(index)
                                .referralStatus,
                            patientName:
                                "${model.getReferredPatientItem(index).firstName} ${model.getReferredPatientItem(index).middleName} ${model.getReferredPatientItem(index).lastName}",
                            patientGender:
                                model.getReferredPatientItem(index).gender,
                            referredDate: DateUtils.convertDateFromServerFormat(
                                model
                                    .getReferredPatientItem(index)
                                    .referralDate,
                                "dd/MM/yyyy"),
                            referredTime: DateUtils.convertDateFromServerFormat(
                                model
                                    .getReferredPatientItem(index)
                                    .referralDate,
                                "hh:mm a"),
                            patientID:
                                "${model.getReferredPatientItem(index).patientID}",
                            isSameBranch: model
                                .getReferredPatientItem(index)
                                .isReferralDoctorSameBranch,
                            isReferral: false,
                            remark: model
                                .getReferredPatientItem(index)
                                .referringDoctorRemarks,
                            nationality: model
                                .getReferredPatientItem(index)
                                .nationalityName,
                            nationalityFlag: model
                                .getReferredPatientItem(index)
                                .nationalityFlagURL,
                            doctorAvatar: model
                                .getReferredPatientItem(index)
                                .doctorImageURL,
                            referralDoctorName:
                                "Dr. ${model.getReferredPatientItem(index).referralDoctorName}",
                            clinicDescription: model
                                .getReferredPatientItem(index)
                                .referralClinicDescription,
                            infoIcon: Icon(FontAwesomeIcons.arrowRight,
                                size: 25, color: Colors.black),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
      ),
    );
  }
}
