import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';

import '../resource/colors.gen.dart';

class LoadingDialog {
  static void show(String msg) {
    SmartDialog.showLoading(msg: msg);
  }

  static void hide() {
    SmartDialog.dismiss();
  }
}

class CustomLoadingDialog {
  static String tag = "CustomLoadingDialog";

  static void show({String? loadingTxt, bool backDismiss = false}) {
    SmartDialog.show(
        tag: tag,
       backType: SmartBackType.block,
        clickMaskDismiss: false,
        builder: (_) {
          return Container(
              padding: EdgeInsets.all(20.w),
              decoration: BoxDecoration(
                color: ColorName.black70,
                borderRadius: BorderRadius.circular(12.w),
              ),
              child: IntrinsicHeight(
                child: Column(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: [
                    CircularProgressIndicator(
                      strokeWidth: 3.w,
                      valueColor:
                          const AlwaysStoppedAnimation(ColorName.white75),
                    ),
                    Visibility(
                        visible: loadingTxt != null,
                        child: SizedBox(height: 12.w)),
                    Builder(builder: (context) {
                      if (loadingTxt == null) {
                        return const SizedBox.shrink();
                      }
                      return Text(loadingTxt,
                          style: TextStyle(
                              fontSize: 13.sp, color: ColorName.white75));
                    })
                  ],
                ),
              ));
        });
  }

  static void hide() {
    SmartDialog.dismiss(tag: tag);
  }
}
