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/utils/date-utils.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/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';

import '../../utils/translations_delegate_base_utils.dart';
import '../../widgets/shared/errors/error_message.dart';
import 'ReferralDischargedPatientDetails.dart';

class ReferralDischargedPatientPage extends StatefulWidget {
  @override
  _ReferralDischargedPatientPageState createState() =>
      _ReferralDischargedPatientPageState();
}

class _ReferralDischargedPatientPageState
    extends State<ReferralDischargedPatientPage> {
  @override
  Widget build(BuildContext context) {
    return BaseView<PatientReferralViewModel>(
      onModelReady: (model) => model.gtMyDischargeReferralPatient(),
      builder: (_, model, w) => AppScaffold(
        appBarTitle: 'Referral Discharged ',
        backgroundColor: Colors.grey[200]!,
        isShowAppBar: false,
        baseViewModel: model,
        body: model.myDischargeReferralPatient.isEmpty
            ? Center(
                child: Container(
                child: ErrorMessage(
                  error: TranslationBase.of(context).referralEmptyMsg,
                ),
              ))
            : Padding(
                padding: const EdgeInsets.all(8.0),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    SizedBox(
                      height: 5,
                    ),
                    Expanded(
                      child: ListView.builder(
                          itemCount: model.myDischargeReferralPatient.length,
                          itemBuilder: (context, index) => InkWell(
                                onTap: () {
                                  Navigator.push(
                                    context,
                                    FadePage(
                                      page: ReferralDischargedPatientDetails(
                                          model.myDischargeReferralPatient[
                                              index]),
                                    ),
                                  );
                                },
                                child: PatientReferralItemWidget(
                                  referralStatus:
                                      model.getReferralStatusNameByCode(
                                          model
                                              .myDischargeReferralPatient[index]
                                              .referralStatus!,
                                          context),
                                  referralStatusCode: model
                                      .myDischargeReferralPatient[index]
                                      .referralStatus!,
                                  patientName: model
                                          .myDischargeReferralPatient[index]
                                          .firstName! +
                                      " " +
                                      model.myDischargeReferralPatient[index]
                                          .lastName!,
                                  patientGender: model
                                      .myDischargeReferralPatient[index].gender!,
                                  referredDate:
                                      AppDateUtils.getDayMonthYearDateFormatted(
                                          model
                                              .myDischargeReferralPatient[index]
                                              .referralDate!),
                                  referredTime: AppDateUtils.getTimeHHMMA(model
                                      .myDischargeReferralPatient[index]
                                      .referralDate!),
                                  patientID:
                                      "${model.myDischargeReferralPatient[index].patientID}",
                                  isSameBranch: false,
                                  isReferral: true,
                                  isReferralClinic: true,
                                  referralClinic:
                                      "${model.myDischargeReferralPatient[index].referringClinicDescription}",
                                  remark: model
                                      .myDischargeReferralPatient[index]
                                      .referringDoctorRemarks!,
                                  nationality: model
                                      .myDischargeReferralPatient[index]
                                      .nationalityName!,
                                  nationalityFlag: '',
                                  //model.myDischargeReferralPatient[index].nationalityFlagURL, //TODO From backend
                                  doctorAvatar: '',
                                  //model.myDischargeReferralPatient[index].doctorImageURL, //TODO From backend
                                  referralDoctorName: model
                                      .myDischargeReferralPatient[index]
                                      .referringDoctorName!,
                                  clinicDescription: model
                                      .myDischargeReferralPatient[index]
                                      .referringClinicDescription!,
                                   infoIcon: Icon(FontAwesomeIcons.arrowRight.data,
                                       size: 25, color: Colors.black),
                                ),
                              )),
                    ),
                  ],
                ),
              ),
      ),
    );
  }
}
