import 'package:auto_size_text/auto_size_text.dart';
import 'package:hmg_patient_app/core/viewModels/project_view_model.dart';
import 'package:hmg_patient_app/theme/colors.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/buttons/defaultButton.dart';
import 'package:hmg_patient_app/widgets/data_display/medical/medical_profile_item.dart';
import 'package:hmg_patient_app/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class AdmissionNotice extends StatefulWidget {
  const AdmissionNotice();

  @override
  State<AdmissionNotice> createState() => _AdmissionNoticeState();
}

class _AdmissionNoticeState extends State<AdmissionNotice> {
  late ProjectViewModel projectViewModel;

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of(context);
    List<Widget> inPatientServiceList = getAdmissionNoticeServicesList(context);
    return AppScaffold(
      isShowAppBar: true,
      isShowDecPage: false,
      showNewAppBarTitle: true,
      showNewAppBar: true,
      appBarTitle: TranslationBase.of(context).admissionNoticeTitle,
      body: Container(
        margin: EdgeInsets.all(20.0),
        child: Column(
          children: [
            Padding(
              padding: EdgeInsets.only(left: 12, right: 12),
              child: GridView.builder(
                shrinkWrap: true,
                primary: false,
                physics: NeverScrollableScrollPhysics(),
                gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, childAspectRatio: 2 / 2, crossAxisSpacing: 12, mainAxisSpacing: 12),
                padding: EdgeInsets.zero,
                itemCount: inPatientServiceList.length,
                itemBuilder: (BuildContext context, int index) {
                  return inPatientServiceList[index];
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

  List<Widget> getAdmissionNoticeServicesList(BuildContext context) {
    List<Widget> serviceList = [];

    serviceList.add(
      InkWell(
        onTap: () {
          // openBirthNotificationsPage(context);
          viewModalBottomSheet();
        },
        child: MedicalProfileItem(
          title: TranslationBase.of(context).admissionNoticeTitle,
          imagePath: 'admission.svg',
          subTitle: TranslationBase.of(context).insuranceSubtitle,
          width: 50.0,
          height: 40.0,
          isInPatient: true,
        ),
      ),
    );

    return serviceList;
  }

  void viewModalBottomSheet() {
    showModalBottomSheet(
        context: context,
        builder: (context) {
          return Column(
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Padding(
                padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
                child: Text(
                  "Admission Card",
                  style: TextStyle(
                    color: Colors.black,
                    fontWeight: FontWeight.bold,
                    fontSize: 21,
                    letterSpacing: -0.25,
                    height: 25 / 17,
                  ),
                ),
              ),
              Container(
                padding: EdgeInsets.all(16.0),
                height: 250,
                child: Container(
                  decoration: cardRadius(20, color: Color(0xFFF2B353E)),
                  clipBehavior: Clip.antiAlias,
                  margin: EdgeInsets.zero,
                  child: Container(
                    width: double.infinity,
                    height: double.infinity,
                    clipBehavior: Clip.antiAlias,
                    margin: EdgeInsets.zero,
                    decoration: projectViewModel.isArabic
                        ? containerBottomRightRadiusWithGradientForAr(MediaQuery.of(context).size.width / 4)
                        : containerBottomRightRadiusWithGradient(MediaQuery.of(context).size.width / 4),
                    child: Card(
                      color: Colors.transparent,
                      margin: EdgeInsets.zero,
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          mFlex(2),
                          Padding(
                            padding: const EdgeInsets.only(left: 20, right: 20),
                            child: Text(
                              projectViewModel.authenticatedUserObject.user.firstName! + " " + projectViewModel.authenticatedUserObject.user.lastName!,
                              style: TextStyle(
                                color: Colors.white,
                                fontWeight: FontWeight.bold,
                                fontSize: 17,
                                letterSpacing: -0.25,
                                height: 25 / 17,
                              ),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(left: 20, right: 20),
                            child: Text(
                              TranslationBase.of(context).roomNo + " " + (projectViewModel.isPatientAdmitted ? projectViewModel.getAdmissionInfoResponseModel.roomID! : "Not assigned yet"),
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 15,
                                letterSpacing: -0.25,
                                height: 25 / 17,
                              ),
                            ),
                          ),
                          mFlex(2),
                          Padding(
                            padding: const EdgeInsets.only(left: 20, right: 20),
                            child: Text(
                              projectViewModel.isPatientAdmitted
                                  ? projectViewModel.getAdmissionInfoResponseModel.doctorName ?? ""
                                  : projectViewModel.getAdmissionRequestInfoResponseModel.doctorName ?? "",
                              style: TextStyle(
                                color: Colors.white,
                                fontWeight: FontWeight.bold,
                                fontSize: 17,
                                letterSpacing: -0.25,
                                height: 25 / 17,
                              ),
                            ),
                          ),
                          // mFlex(2),
                          Padding(
                            padding: const EdgeInsets.only(left: 20, right: 20),
                            child: Text(
                              TranslationBase.of(context).clinic +
                                  ": " +
                                  (projectViewModel.isPatientAdmitted
                                      ? projectViewModel.getAdmissionInfoResponseModel.clinicName!.toString()
                                      : projectViewModel.getAdmissionRequestInfoResponseModel.clinicName!),
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 15,
                                letterSpacing: -0.25,
                                height: 25 / 17,
                              ),
                            ),
                          ),
                          Padding(
                            padding: const EdgeInsets.only(left: 20, right: 20),
                            child: Text(
                              TranslationBase.of(context).hospital +
                                  ": " +
                                  (projectViewModel.isPatientAdmitted
                                      ? projectViewModel.getAdmissionInfoResponseModel.projectName!.toString()
                                      : projectViewModel.getAdmissionRequestInfoResponseModel.projectName!),
                              style: TextStyle(
                                color: Colors.white,
                                fontSize: 15,
                                letterSpacing: -0.25,
                                height: 25 / 17,
                              ),
                            ),
                          ),
                          mFlex(1),
                        ],
                      ),
                    ),
                  ),
                ),
              ),
              Padding(
                padding: const EdgeInsets.only(left: 20, right: 20, bottom: 30),
                child: DefaultButton(
                  TranslationBase.of(context).close.toUpperCase(),
                  () {
                    Navigator.pop(context);
                  },
                  color: CustomColors.accentColor,
                  disabledColor: CustomColors.grey2,
                ),
              ),
            ],
          );
        });
  }
}
