import 'dart:developer';

import 'package:flutter/material.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/widget_extensions.dart';
import 'package:hmg_patient_app_new/services/navigation_service.dart';
import 'package:hmg_patient_app_new/theme/colors.dart';

class LoadingUtils {
  static final NavigationService _navigationService = getIt.get<NavigationService>();

  static bool _isLoadingVisible = false;

  static bool get isLoading => _isLoadingVisible;

  // static showFullScreenLoader({bool barrierDismissible = true, isSuccessDialog = false, String loadingText = "Loading, Please wait..."}) {
  //   if (!_isLoadingVisible) {
  //     _isLoadingVisible = true;
  //     final context = _navigationService.navigatorKey.currentContext;
  //     log("got the context in showFullScreenLoading");
  //     if (context == null) return;
  //
  //     showDialog(
  //         barrierDismissible: barrierDismissible,
  //         context: context,
  //         barrierColor: AppColors.blackColor.withOpacity(0.5),
  //         useRootNavigator: false,
  //         useSafeArea: false,
  //         builder: (BuildContext context) {
  //           return Container(
  //             decoration: RoundedRectangleBorder().toSmoothCornerDecoration(
  //               color: AppColors.whiteColor,
  //               borderRadius: 20.h,
  //               hasShadow: false,
  //             ),
  //             child: Material(
  //               child: Center(
  //                 child: isSuccessDialog ? Utils.getSuccessWidget(loadingText: loadingText) : Utils.getLoadingWidget(loadingText: loadingText),
  //               ).paddingSymmetrical(24.w, 0),
  //             ),
  //           );
  //         }).then((value) {
  //       _isLoadingVisible = false;
  //     });
  //   }
  // }

  static hideFullScreenLoader() {
    if (!_isLoadingVisible) return;

    final context = _navigationService.navigatorKey.currentContext;
    if (context != null) {
      try {
        Navigator.of(context).pop();
      } catch (_) {}
    }
    _isLoadingVisible = false;
  }
}
