import 'package:hmg_patient_app/core/viewModels/medical/reports_view_model.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/pages/base/base_view.dart';
import 'package:hmg_patient_app/pages/feedback/appointment_history.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/date_uitl.dart';
import 'package:hmg_patient_app/uitl/translations_delegate_base.dart';
import 'package:hmg_patient_app/uitl/utils_new.dart';
import 'package:hmg_patient_app/widgets/avatar/large_avatar.dart';
import 'package:hmg_patient_app/widgets/dialogs/ConfirmWithMessageDialog.dart';
import 'package:hmg_patient_app/widgets/my_rich_text.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_rating_bar/flutter_rating_bar.dart';
import 'package:provider/provider.dart';

class MedicalReports extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    void confirmBox(AppointmentHistory model, ReportsViewModel reportsViewModel) {
      showDialog(
        context: context,
        builder: (cxt) => ConfirmWithMessageDialog(
          message: TranslationBase.of(context).confirmMsgReport,
          onTap: () => reportsViewModel.insertRequestForMedicalReport(model, TranslationBase.of(context).successSendReport),
        ),
      ).then((value) {
        Navigator.pop(context);
      });
      return;
    }

    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<ReportsViewModel>(
      onModelReady: (model) => model.getPatentAppointmentHistory(),
      builder: (_, model, widget) => AppScaffold(
        baseViewModel: model,
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).medReport,
        showNewAppBar: true,
        showNewAppBarTitle: true,
        backgroundColor: Color(0xffF7F7F7),
        body: model.appointHistoryList.isEmpty
            ? getNoDataWidget(context)
            : ListView.separated(
                physics: BouncingScrollPhysics(),
                itemCount: model.appointHistoryList.length,
                padding: EdgeInsets.all(21),
                separatorBuilder: (context, index) => SizedBox(height: 14),
                itemBuilder: (context, index) {
                  AppointmentHistory _appointmenHistory = model.appointHistoryList[index];
                  return InkWell(
                    onTap: () => confirmBox(model.appointHistoryList[index], model),
                    child: Container(
                      decoration: BoxDecoration(
                          borderRadius: BorderRadius.all(
                            Radius.circular(10.0),
                          ),
                          boxShadow: [
                            BoxShadow(
                              color: Color(0xff000000).withOpacity(.05),
                              //spreadRadius: 5,
                              blurRadius: 27,
                              offset: Offset(0, -3),
                            ),
                          ],
                          color: Colors.white),
                      child: Padding(
                        padding: const EdgeInsets.only(left: 12, right: 12, top: 12, bottom: 12),
                        child: Column(
                          mainAxisSize: MainAxisSize.min,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: [
                                if ((_appointmenHistory.doctorName ?? _appointmenHistory.doctorNameObj) != null)
                                  Text(
                                    _appointmenHistory.doctorTitle.toString() + " " + (_appointmenHistory.doctorName ?? _appointmenHistory.doctorNameObj),
                                    style: TextStyle(fontSize: 16, fontWeight: FontWeight.w600, color: Color(0xff2E303A), letterSpacing: -0.64, height: 25 / 16),
                                  ),
                                Text(
                                  DateUtil.getDayMonthYearDateFormatted(_appointmenHistory.appointmentDate!),
                                  style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600, color: Color(0xff2B353E), letterSpacing: -0.48, height: 18 / 12),
                                ),
                              ],
                            ),
                            if ((_appointmenHistory.doctorName ?? _appointmenHistory.doctorNameObj) != null) SizedBox(height: 6),
                            Row(
                              mainAxisSize: MainAxisSize.min,
                              children: <Widget>[
                                LargeAvatar(
                                  name: _appointmenHistory.doctorName,
                                  url: _appointmenHistory.doctorImageURL,
                                  width: 48,
                                  height: 48,
                                ),
                                SizedBox(width: 11),
                                Expanded(
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    mainAxisSize: MainAxisSize.min,
                                    children: <Widget>[
                                      if (_appointmenHistory.projectName != null) MyRichText(TranslationBase.of(context).clinic + ":", _appointmenHistory.projectName!, projectViewModel.isArabic),
                                      if (_appointmenHistory.clinicName != null) MyRichText(TranslationBase.of(context).hospital + ":", _appointmenHistory.clinicName!, projectViewModel.isArabic),
                                      Row(
                                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                        mainAxisSize: MainAxisSize.max,
                                        crossAxisAlignment: CrossAxisAlignment.start,
                                        children: <Widget>[
                                          RatingBar(
                                            initialRating: _appointmenHistory.actualDoctorRate!.toDouble(),
                                            itemSize: 16,
                                            ratingWidget: RatingWidget(
                                              full: Icon(
                                                Icons.star,
                                                color: CustomColors.accentColor,
                                              ),
                                              half: Icon(
                                                Icons.star_half,
                                                color: CustomColors.accentColor,
                                              ),
                                              empty: Icon(
                                                Icons.star_border,
                                                color: CustomColors.accentColor,
                                              ),
                                            ),
                                            onRatingUpdate: (double value) {},
                                            unratedColor: Colors.grey[500],
                                            updateOnDrag: false,
                                            tapOnlyMode: false,
                                          ),
                                          Icon(Icons.email, color: Color(0xff2B353E))
                                        ],
                                      ),
                                    ],
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ),
                  );
                },
              ),
      ),
    );
  }
}
