//
//  MBProgressHUD+Extention.m
//  fastservice
//
//  Created by xuning on 5/5/25.
//  Copyright © 2025 FastService. All rights reserved.
//

#import "MBProgressHUD+Extention.h"

@implementation MBProgressHUD (Extention)

+ (MBProgressHUD *)showMessage:(NSString *)message toView:(UIView *)view {
//    if (!message.length) {
//        return nil;
//    }
    if (message == nil || message.length < 1) {
        return nil;
    }
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    
    
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;

    
    hud.bezelView.color =  [UIColor colorWithWhite:0 alpha:0.4];

    hud.userInteractionEnabled = NO;
    hud.mode = MBProgressHUDModeText;
    hud.detailsLabel.text = message;
    hud.detailsLabel.font = [UIFont systemFontOfSize:16];
    hud.detailsLabel.textColor = [UIColor whiteColor];
    
    hud.removeFromSuperViewOnHide = YES;
    [hud hideAnimated:YES afterDelay:2];
    return hud;
}

+ (MBProgressHUD *)showMessage:(NSString *)message {
    return [MBProgressHUD showMessage:message toView:nil];
}
/**
 需要主动关闭
 */
+ (MBProgressHUD *)showLoading:(NSString *)message toView:(UIView *)view {
    
    if (view == nil) view = [UIApplication sharedApplication].keyWindow;
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:view animated:YES];
    hud.bezelView.style = MBProgressHUDBackgroundStyleSolidColor;

    hud.contentColor = [UIColor whiteColor];
    hud.bezelView.color =  [UIColor colorWithWhite:0 alpha:0.4];

    hud.userInteractionEnabled = NO;
    hud.mode = MBProgressHUDModeIndeterminate;
    if (message.length > 0) {
        hud.label.text = message;
        hud.label.font = [UIFont systemFontOfSize:14];
        hud.label.textColor = [UIColor whiteColor];

    }
    hud.removeFromSuperViewOnHide = YES;
    
    return hud;
}

@end
