import 'package:doctor_app_flutter/config/size_config.dart';
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/patients/profile/profile-welcome-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: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: AppText(
                  TranslationBase.of(context).referralEmptyMsg,
                  color: Theme.of(context).errorColor,
                ),
              )
            : SingleChildScrollView(
                child: Container(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      SizedBox(height: 100),
                      ProfileWelcomeWidget(
                        AppText(
                          authProvider.selectedClinicName != null
                              ? authProvider.selectedClinicName
                              : authProvider.doctorProfile.clinicDescription,
                          fontSize: SizeConfig.textMultiplier * 1.7,
                          color: Colors.white,
                          textAlign: TextAlign.center,
                        ),
                        height: 100,
                      ),
                      SizedBox(
                        height: 16,
                      ),
                      Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 16.0),
                        child: AppText(
                          TranslationBase.of(context).myReferralPatient,
                          color: Colors.black,
                          fontWeight: FontWeight.bold,
                          fontSize: 16,
                        ),
                      ),
                      ...List.generate(
                        model.pendingReferral.length,
                        (index) => InkWell(
                          onTap: () {
                            Navigator.of(context).pushNamed(MY_REFERRAL_DETAIL,
                                arguments: {
                                  'referral': model.pendingReferral[index]
                                });
                          },
                          child: PatientReferralItemWidget(
                            "${model.pendingReferral[index].patientID}",
                            patientName:
                                model.pendingReferral[index].patientName,
                            referralStatus: null,
                            isReferredTo: false,
                            isSameBranch: model.pendingReferral[index]
                                .isReferralDoctorSameBranch,
                            referralDoctorName: model
                                .pendingReferral[index].referredByDoctorInfo,
                            clinicDescription: null,
                            remark:
                                model.pendingReferral[index].remarksFromSource,
                            referredOn: model.pendingReferral[index].referredOn,
                            answerFromTarget:
                                model.pendingReferral[index].answerFromTarget,
                            infoIcon: InkWell(
                              onTap: () {
                                Navigator.of(context)
                                    .pushNamed(MY_REFERRAL_DETAIL, arguments: {
                                  'referral': model.pendingReferral[index]
                                });
                              },
                              child: Icon(
                                Icons.info_outline,
                                color: Colors.black,
                                size: 30,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
      ),
    );
  }
}
