import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/services/clinic_services/get_clinic_service.dart';
import 'package:hmg_patient_app/theme/colors.dart';
import 'package:hmg_patient_app/uitl/app_toast.dart';
import 'package:hmg_patient_app/uitl/gif_loader_dialog_utils.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/buttons/custom_text_button.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class InPatientGeneralConsent extends StatelessWidget {
  late ProjectViewModel projectViewModel;

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of(context);
    return AppScaffold(
      isShowAppBar: true,
      isShowDecPage: false,
      showNewAppBarTitle: true,
      showNewAppBar: true,
      appBarTitle: TranslationBase.of(context).InPatientServicesHeader,
      body: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisSize: MainAxisSize.min,
        children: [
          Padding(
            padding: const EdgeInsets.all(21.0),
            child: Text(
              TranslationBase.of(context).generalConsent,
              overflow: TextOverflow.clip,
              style: TextStyle(
                fontSize: 21.0,
                fontWeight: FontWeight.bold,
                color: Color(0xff2B353E),
                letterSpacing: -0.64,
              ),
            ),
          ),
          Expanded(
            child: SingleChildScrollView(
              child: Container(
                width: MediaQuery.of(context).size.width,
                child: Card(
                  elevation: 0.0,
                  margin: EdgeInsets.only(left: 16.0, right: 16.0, bottom: 16.0),
                  color: Colors.white,
                  shape: RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(10),
                    side: BorderSide(color: Colors.transparent, width: 0.0),
                  ),
                  child: Padding(
                    padding: EdgeInsets.all(16.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent1,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).hospitalRules,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent2,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).communicationConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent3,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).releaseConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent4,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent5,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).valuables,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent6,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).financialConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent7,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).dataSharingConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent8,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).permissionLeaveConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent9,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).observeConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent10,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).noGuaranteeConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent11,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).disputeConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent12,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).patientsRightsConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent13,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(24.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).acknowledgementConsent,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 21.0,
                              fontWeight: FontWeight.bold,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                        mHeight(12.0),
                        Container(
                          width: MediaQuery.of(context).size.width * 0.85,
                          margin: EdgeInsets.only(left: 5.0, right: 5.0),
                          child: Text(
                            TranslationBase.of(context).generalConsent14,
                            overflow: TextOverflow.clip,
                            style: TextStyle(
                              fontSize: 14.0,
                              fontWeight: FontWeight.w600,
                              color: Color(0xff2B353E),
                              letterSpacing: -0.64,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(left: 21.0, right: 21.0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: <Widget>[
                Expanded(
                  flex: 1,
                  child: ButtonTheme(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10.0),
                    ),
                    height: 45.0,
                    child: CustomTextButton(
                      backgroundColor: Color(0xffc5272d),
                      elevation: 0,
                      onPressed: () {
                        acceptRejectConsent(context, 0);
                      },
                      child: Text(TranslationBase.of(context).reject, style: TextStyle(fontSize: 16.0, color: Colors.white)),
                    ),
                  ),
                ),
                mWidth(7),
                Expanded(
                  flex: 1,
                  child: ButtonTheme(
                    shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(10.0),
                    ),
                    height: 45.0,
                    child: CustomTextButton(
                      backgroundColor: CustomColors.green,
                      elevation: 0,
                      onPressed: () {
                        acceptRejectConsent(context, 1);
                      },
                      child: Text(TranslationBase.of(context).acceptLbl, style: TextStyle(fontSize: 16.0, color: Colors.white)),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  void acceptRejectConsent(BuildContext context, int status) {
    ClinicListService service = new ClinicListService();
    GifLoaderDialogUtils.showMyDialog(context);
    service
        .insertForGeneralAdmissionConsent(
            projectViewModel.user.patientID!,
            projectViewModel.isPatientAdmitted ? projectViewModel.getAdmissionInfoResponseModel.admissionRequestNo! : projectViewModel.getAdmissionRequestInfoResponseModel.admissionRequestNo!,
            projectViewModel.isPatientAdmitted ? projectViewModel.getAdmissionInfoResponseModel.clinicID! : projectViewModel.getAdmissionRequestInfoResponseModel.clinicId!,
            projectViewModel.isPatientAdmitted ? projectViewModel.getAdmissionInfoResponseModel.projectID! : projectViewModel.getAdmissionRequestInfoResponseModel.projectId!,
            status,
            context)
        .then((res) {
      GifLoaderDialogUtils.hideDialog(context);
      if (res["MessageStatus"] == 1) {
        AppToast.showSuccessToast(message: res["SuccessMsg"] ?? TranslationBase.of(context).success);
        Navigator.of(context);
      } else {
        AppToast.showErrorToast(message: res["endUserMessage"]);
      }
      Navigator.pop(context);
    }).catchError((err) {
      GifLoaderDialogUtils.hideDialog(context);
      print(err);
    });
  }
}
