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/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:flutter/material.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,
        appBarTitle: TranslationBase.of(context).referredPatient,
        body: model.listMyReferredPatientModel == null ||
                model.listMyReferredPatientModel.length == 0
            ? Center(
                child: AppText(
                  TranslationBase.of(context).referralEmptyMsg,
                  color: Theme.of(context).errorColor,
                ),
              )
            : SingleChildScrollView(
                child: Container(
                  child: Column(
                    children: [
                      /*Container(
                        height: 75,
                        child: AppText(
                          "This is where upper view for avatar.. etc placed",
                          fontWeight: FontWeight.normal,
                          fontSize: 16,
                        ),
                      ),*/
                      const Divider(
                        color: Color(0xffCCCCCC),
                        height: 1,
                        thickness: 2,
                        indent: 0,
                        endIndent: 0,
                      ),
                      ...List.generate(
                        model.listMyReferredPatientModel.length,
                        (index) => PatientReferralItemWidget(
                          "${model.getReferredPatientItem(index).patientId}",
                          patientName:
                              "${model.getReferredPatientItem(index).firstName} ${model.getReferredPatientItem(index).middleName} ${model.getReferredPatientItem(index).lastName}",
                          referralStatus:
                              "${model.getReferralStatusNameByCode(model.getReferredPatientItem(index).referralStatus, context)}",
                          isReferredTo: true,
                          isSameBranch: model
                              .getReferredPatientItem(index)
                              .isReferralDoctorSameBranch,
                          referralDoctorName: model
                              .getReferredPatientItem(index)
                              .referralDoctorName,
                          clinicDescription: model
                              .getReferredPatientItem(index)
                              .referralClinicDescription,
                          remark: model
                              .getReferredPatientItem(index)
                              .referringDoctorRemarks,
                          referredOn: model
                                      .getReferredPatientItem(index)
                                      .referralDate !=
                                  null
                              ? DateUtils.convertDateFromServerFormat(model.getReferredPatientItem(index).referralDate, "dd/MM/yyyy")
                              : null,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
      ),
    );
  }
}
