import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.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/route_extensions.dart';
import 'package:hmg_patient_app_new/extensions/string_extensions.dart';
import 'package:hmg_patient_app_new/features/hmg_services/hmg_services_view_model.dart';
import 'package:hmg_patient_app_new/features/hmg_services/models/req_models/order_update_req_model.dart';
import 'package:hmg_patient_app_new/features/hmg_services/models/resq_models/get_cmc_all_orders_resp_model.dart';
import 'package:hmg_patient_app_new/generated/locale_keys.g.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/loader/bottomsheet_loader.dart';
import 'package:provider/provider.dart';

class HhcUiSelectionHelper {
  static void showCancelConfirmationDialog({
    required BuildContext context,
    required GetCMCAllOrdersResponseModel order,
  }) {
    final HmgServicesViewModel hmgServicesViewModel = context.read<HmgServicesViewModel>();

    return showCommonBottomSheetWithoutHeight(
      title: LocaleKeys.notice.tr(context: context),
      context,
      child: Utils.getWarningWidget(
        loadingText: LocaleKeys.cancelOrderConfirmation.tr(context: context),
        isShowActionButtons: true,
        onCancelTap: () {
          Navigator.pop(context);
        },
        onConfirmTap: () async {
          Navigator.pop(context);
          LoaderBottomSheet.showLoader();

          final requestModel = OrderUpdateRequestModel(
            presOrderID: order.iD,
            rejectionReason: "Cancelled by user",
            presOrderStatus: 4, // Cancelled status
            editedBy: 3,
          );

          await hmgServicesViewModel.updateHhcPresOrder(
            requestModel: requestModel,
            onSuccess: (_) async {
              LoaderBottomSheet.hideLoader();
              showCommonBottomSheetWithoutHeight(
                context,
                child: Padding(
                  padding: EdgeInsets.all(16.w),
                  child: Column(
                    children: [
                      Utils.getSuccessWidget(loadingText: LocaleKeys.orderCancelledSuccessfully.tr(context: context)),
                      SizedBox(height: 24.h),
                      Row(
                        children: [
                          Expanded(
                            child: CustomButton(
                              height: 56.h,
                              text: LocaleKeys.ok.tr(),
                              onPressed: () {
                                context.pop();
                                hmgServicesViewModel.getAllHhcOrders();
                              },
                              textColor: AppColors.whiteColor,
                            ),
                          ),
                        ],
                      ),
                    ],
                  ),
                ),
                isCloseButtonVisible: false,
                isDismissible: false,
                isFullScreen: false,
              );
            },
            onError: (error) {
              LoaderBottomSheet.hideLoader();
            },
          );
        },
      ),
      callBackFunc: () {},
      isFullScreen: false,
      isCloseButtonVisible: true,
    );
  }
}
