import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:get_it/get_it.dart';
import 'package:hmg_patient_app_new/core/app_assets.dart';
import 'package:hmg_patient_app_new/core/app_state.dart';
import 'package:hmg_patient_app_new/core/dependencies.dart';
import 'package:hmg_patient_app_new/core/utils/size_utils.dart';
import 'package:hmg_patient_app_new/core/utils/utils.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/extensions/widget_extensions.dart';
import 'package:hmg_patient_app_new/features/inpatient_services/inpatient_services_view_model.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';
import 'package:hmg_patient_app_new/widgets/buttons/custom_button.dart';
import 'package:hmg_patient_app_new/widgets/common_bottom_sheet.dart';
import 'package:hmg_patient_app_new/widgets/input_widget.dart';
import 'package:hmg_patient_app_new/widgets/loader/bottomsheet_loader.dart';

import '../../../generated/locale_keys.g.dart';

class PatientRelationOfficeWidget extends StatelessWidget {
  PatientRelationOfficeWidget({super.key, required this.inPatientServicesViewModel});

  InpatientServicesViewModel inPatientServicesViewModel;
  final TextEditingController notesTextController = TextEditingController();
  late AppState appState;

  @override
  Widget build(BuildContext context) {
    appState = getIt.get<AppState>();
    return Padding(
      padding: EdgeInsets.all(16.h),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          "How we may assist you?".toText16(isBold: true),
          SizedBox(
            height: 16.h,
          ),
          TextInputWidget(
            padding: EdgeInsets.all(8.h),
            labelText: LocaleKeys.details.tr(context: context),
            hintText: "",
            controller: notesTextController,
            keyboardType: TextInputType.text,
            isEnable: true,
            prefix: null,
            autoFocus: true,
            isAllowRadius: true,
            isBorderAllowed: false,
            isAllowLeadingIcon: true,
            leadingIcon: AppAssets.notes_icon,
            hasError: false,
            errorMessage: "",
          ),
          SizedBox(
            height: 24.h,
          ),
          CustomButton(
            text: LocaleKeys.send.tr(context: context),
            onPressed: () {
              LoaderBottomSheet.showLoader();
              inPatientServicesViewModel.insertInPatientOrder(
                  getAdmissionInfoResponseModel: inPatientServicesViewModel.getAdmissionInfoResponseModel!,
                  typeID: 1,
                  patientName: "${appState.getAuthenticatedUser()!.firstName!} ${appState.getAuthenticatedUser()!.lastName!}",
                  patientNameAR: "${appState.getAuthenticatedUser()!.firstNameN!} ${appState.getAuthenticatedUser()!.lastNameN!}",
                  patientMobileNo: appState.getAuthenticatedUser()!.mobileNumber!,
                  comments: notesTextController.text,
                  onError: (String errorMessage) {
                    LoaderBottomSheet.hideLoader();
                    showCommonBottomSheetWithoutHeight(GetIt.instance<NavigationService>().navigatorKey.currentContext!,
                        child: Utils.getErrorWidget(loadingText: errorMessage).paddingSymmetrical(0.h, 24.h),
                        callBackFunc: () {},
                        isFullScreen: false,
                        isCloseButtonVisible: false,
                        isAutoDismiss: true);
                  },
                  onSuccess: (val) {
                    LoaderBottomSheet.hideLoader();
                    showCommonBottomSheetWithoutHeight(GetIt.instance<NavigationService>().navigatorKey.currentContext!,
                        child: Utils.getSuccessWidget(loadingText: LocaleKeys.requestSubmittedSuccessfully.tr()).paddingSymmetrical(0.h, 24.h), callBackFunc: () {
                      Navigator.of(context).pop();
                    }, isFullScreen: false, isCloseButtonVisible: false, isAutoDismiss: true);
                  });
            },
            backgroundColor: AppColors.primaryRedColor,
            borderColor: AppColors.primaryRedColor,
            textColor: Colors.white,
            fontSize: 16,
            fontWeight: FontWeight.w600,
            borderRadius: 12,
            padding: EdgeInsets.fromLTRB(10, 0, 10, 0),
            height: 50.h,
            icon: AppAssets.sendEmailIcon,
            iconColor: Colors.white,
            iconSize: 18.h,
          ),
        ],
      ),
    );
  }
}
