//
//  CCAlert.swift
//  SwiftProject
//
//  Created by soldoros on 2024/1/10.
//

import UIKit

/// 系统提示框按钮点击回调代码块 点击的action
typealias AlertBlock = (_ action:UIAlertAction) -> ()

class CCAlert: NSObject {

    class func pressentAlertControllerWith(title:NSString, message:NSString, ok:NSString, cancel:NSString, alertBlock:@escaping AlertBlock){
        
        let alert:UIAlertController = UIAlertController.init(title: title as String, message: message as String, preferredStyle: UIAlertController.Style.alert)
        
        if(ok.length != 0){
            let defaultAction:UIAlertAction = UIAlertAction.init(title: ok as String, style: UIAlertAction.Style.default) { (action) in
                alertBlock(action)
            }
            defaultAction.setValue(TitleColor, forKey: "_titleTextColor")
            alert.addAction(defaultAction)
        }
        if(cancel.length != 0){
            let cancelAction:UIAlertAction = UIAlertAction.init(title: cancel as String, style: UIAlertAction.Style.cancel) { (action) in
                alertBlock(action)
            }
            cancelAction.setValue(TitleColor, forKey: "_titleTextColor")
            alert.addAction(cancelAction)
        }
        let controller:UIViewController = KWindow!.rootViewController!
        
        controller.present(alert, animated: true, completion: nil)
    }
    
    
}
