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,
        isShowAppBar: false,
        appBarTitle: TranslationBase.of(context).referredPatient,
        body: model.listMyReferredPatientModel == null ||
                model.listMyReferredPatientModel.length == 0
            ? 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(
                  TranslationBase.of(context).referralEmptyMsg,
                  color: Theme.of(context).errorColor,
                ),
              )
            ],
          ),
        )
            : SingleChildScrollView(
                child: Container(
                  child: Column(
                    children: [
                      const Divider(
                        color: Color(0xffCCCCCC),
                        height: 1,
                        thickness: 2,
                        indent: 0,
                        endIndent: 0,
                      ),
                      ...List.generate(
                        model.listMyReferredPatientModel.length,
                        (index) =>
                            PatientReferralItemWidget(
                              referralStatus: "${model.getReferralStatusNameByCode(model.getReferredPatientItem(index).referralStatus, context)}",
                              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: " ",
                              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: "${model.getReferredPatientItem(index).referringDoctorName}(${model.getReferredPatientItem(index).referringClinicDescription})",
                              clinicDescription: null,
                            ),
                      ),
                    ],
                  ),
                ),
              ),
      ),
    );
  }
}
