import 'package:doctor_app_flutter/core/viewModel/auth_view_model.dart';
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/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';
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
import 'package:provider/provider.dart';

import '../../../../routes.dart';

class MyReferralPatientScreen extends StatelessWidget {
  // previous design page is: MyReferralPatient
  @override
  Widget build(BuildContext context) {
    AuthViewModel authProvider = Provider.of(context);

    return BaseView<PatientReferralViewModel>(
      onModelReady: (model) => model.getPendingReferralPatients(),
      builder: (_, model, w) => AppScaffold(
        baseViewModel: model,
        isShowAppBar: false,
        appBarTitle: TranslationBase.of(context).referPatient,
        body: model.pendingReferral == null || model.pendingReferral.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(
                  margin: EdgeInsets.only(top: 70),
                  // color: Colors.white,
                  // height: MediaQuery.of(context).size.height,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      // SizedBox(height: 50),
                      ...List.generate(
                        model.pendingReferral.length,
                        (index) => InkWell(
                          onTap: () {
                            Navigator.of(context).pushNamed(MY_REFERRAL_DETAIL,
                                arguments: {
                                  'referral': model.pendingReferral[index]
                                });
                          },
                          child: PatientReferralItemWidget(
                            referralStatus:
                                model.pendingReferral[index].referralStatus,
                            patientName:
                                model.pendingReferral[index].patientName,
                            patientGender: model
                                .pendingReferral[index].patientDetails.gender,
                            referredDate: model
                                .pendingReferral[index].referredOn
                                .split(" ")[0],
                            referredTime: model
                                .pendingReferral[index].referredOn
                                .split(" ")[1],
                            patientID:
                                "${model.pendingReferral[index].patientID}",
                            isSameBranch: model.pendingReferral[index]
                                .isReferralDoctorSameBranch,
                            isReferral: true,
                            remark:
                                model.pendingReferral[index].remarksFromSource,
                            nationality: model.pendingReferral[index]
                                .patientDetails.nationalityName,
                            nationalityFlag:
                                model.pendingReferral[index].nationalityFlagUrl,
                            doctorAvatar:
                                model.pendingReferral[index].doctorImageUrl,
                            referralDoctorName: model
                                .pendingReferral[index].referredByDoctorInfo,
                            clinicDescription: null,
                            infoIcon: InkWell(
                              onTap: () {
                                Navigator.of(context)
                                    .pushNamed(MY_REFERRAL_DETAIL, arguments: {
                                  'referral': model.pendingReferral[index]
                                });
                              },
                              child: Icon(FontAwesomeIcons.arrowRight,
                                  size: 25, color: Colors.black),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
      ),
    );
  }
}
