//
//  UIAlertController+gm.m
//  AFNetworking
//
//  Created by Q14 on 2019/12/18.
//

#import "UIAlertController+gm.h"

@implementation UIAlertController (gm)
//@objc static func showOKAlert(withTitle title: String?, message: String? = nil, actionTitle: String = "好", actionHandler: (() -> Void)? = nil) {
//      let alert = UIAlertController(title: title, message: message, preferredStyle: .alert)
//      let action = UIAlertAction(title: actionTitle, style: .default) { (_) in
//          actionHandler?()
//      }
//      alert.addAction(action)
//      UIApplication.shared.keyWindow?.rootViewController?.present(alert, animated: true, completion: nil)
//  }

- (void)showgm_OKAlertWithTitle:(NSString *)title message:(NSString *)message actionTitle:(NSString *)actionTitle actionHandler:(void(^)(void))actionHandler {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:message preferredStyle:UIAlertControllerStyleAlert];
//     __weak typeof(self)weakSelf = self;
    UIAlertAction *action = [UIAlertAction actionWithTitle:actionTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (actionHandler) {
            actionHandler();
        }
    }];
    [alert addAction:action];
    [UIApplication.sharedApplication.keyWindow.rootViewController presentViewController:alert animated:YES completion:NULL];
}

- (void)gm_Alert:(NSString *)title leftTitle:(NSString *)leftTitle rightTitle:(NSString *)rightTitle leftAlterAction:(void(^)(void))leftAlterAction  rightAlertAction:(void(^)(void))rightAlertAction {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:@"" preferredStyle:UIAlertControllerStyleAlert];
//     __weak typeof(self)weakSelf = self;
    UIAlertAction *leftAction = [UIAlertAction actionWithTitle:leftTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (leftAlterAction) {
            leftAlterAction();
        }
    }];
    [alert addAction:leftAction];

    
    UIAlertAction *rightAction = [UIAlertAction actionWithTitle:rightTitle style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        if (rightAlertAction) {
            rightAlertAction();
        }
    }];
    [alert addAction:rightAction];
    [UIApplication.sharedApplication.keyWindow.rootViewController presentViewController:alert animated:YES completion:NULL];
}

@end
