import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart';
import 'package:diplomaticquarterapp/core/model/sick_leave/sick_leave.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/patient_sick_leave_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/medical/doctor_card.dart';
import 'package:diplomaticquarterapp/widgets/dialogs/confirm_send_email_dialog.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PatientSickLeavePage extends StatefulWidget {
  @override
  _PatientSickLeavePageState createState() => _PatientSickLeavePageState();
}

class _PatientSickLeavePageState extends State<PatientSickLeavePage> {
  List<ImagesInfo> imagesInfo = List();

  @override
  void initState() {
    imagesInfo.add(ImagesInfo(
        imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/sick-leaves/en/0.png',
        imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/sick-leaves/ar/0.png'));
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<PatientSickLeaveViewMode>(
      onModelReady: (model) => model.getSickLeave(),
      builder: (_, model, w) => AppScaffold(
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).sickLeaves,
        description: TranslationBase.of(context).infoSickLeaves,
        infoList: TranslationBase.of(context).infoSickLeavePoints,
        imagesInfo: imagesInfo,
        baseViewModel: model,
        body: Container(
          margin: EdgeInsets.all(12),
          child: ListView.builder(
            itemCount: model.sickLeaveList.length,
            itemBuilder: (context, index) => DoctorCard(
              isLiveCareAppointment: model.sickLeaveList[index].isLiveCareAppointment,
              name: model.sickLeaveList[index].doctorName,
              date:projectViewModel.isArabic? DateUtil.getMonthDayYearDateFormattedAr(model.sickLeaveList[index].appointmentDate):DateUtil.getMonthDayYearDateFormatted(model.sickLeaveList[index].appointmentDate),
              profileUrl: model.sickLeaveList[index].doctorImageURL,
              rat: model.sickLeaveList[index].actualDoctorRate.toDouble(),
              subName: model.sickLeaveList[index].projectName,
              isInOutPatient: model.sickLeaveList[index].isInOutPatient,
              onEmailTap: () {
                showConfirmMessage(model, index);
              },
            ),
          ),
        ),
      ),
    );
  }

  void showConfirmMessage(PatientSickLeaveViewMode model, int index) {
    showDialog(
      context: context,
      child: ConfirmSendEmailDialog(
        email: model.user.emailAddress,
        onTapSendEmail: () {
          model.sendSickLeaveEmail(
              message: TranslationBase.of(context).emailSentSuccessfully,
              requestNo: model.sickLeaveList[index].requestNo,
              doctorName: model.sickLeaveList[index].doctorName,
              projectName: model.sickLeaveList[index].projectName,
              setupID: model.sickLeaveList[index].setupID,
              projectID: model.sickLeaveList[index].projectID);
        },
      ),
    );
  }
}
