//
//  LAHudManager.swift
//  Bole
//
//  Created by 张思源 on 2018/12/27.
//  Copyright © 2018 huatec. All rights reserved.
//

import Foundation
import SVProgressHUD

let dismissDelay : Double = 2.0

struct LAHudManager {
    
    static func showWithMessage(_ msg : String? = "请稍候..." , canInteractive : Bool = false) {

        if canInteractive {
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.none)
        }else{
            SVProgressHUD.setDefaultMaskType(SVProgressHUDMaskType.black)
        }
        SVProgressHUD.setDefaultStyle(SVProgressHUDStyle.dark)
        
        SVProgressHUD.show(withStatus: msg)
        
    }
    
    static func dismiss() {
        SVProgressHUD.dismiss()
    }
    
    static func showSuccessWithMessage(_ msg : String,  delay : Double = dismissDelay) {
        SVProgressHUD.setDefaultStyle(SVProgressHUDStyle.dark)

        SVProgressHUD.setSuccessImage(UIImage(named: "tips_success")!)
        
        SVProgressHUD.showSuccess(withStatus: msg)
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + dismissDelay) {
            SVProgressHUD.dismiss()
        }

        
    }
    
    static func showFailureWithMessage(_ msg : String? = "无法连接到服务器~", delay : Double = dismissDelay) {
        
        SVProgressHUD.setDefaultStyle(SVProgressHUDStyle.dark)

        SVProgressHUD.setErrorImage(UIImage(named: "tips_fail")!)
        
        SVProgressHUD.showError(withStatus: msg)
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay) {
            SVProgressHUD.dismiss()
        }

    }
    
    static func showInfo(_ msg : String? , delay : Double = dismissDelay){
        SVProgressHUD.setDefaultStyle(SVProgressHUDStyle.dark)
        
        SVProgressHUD.showInfo(withStatus: msg)
        
        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delay) {
            SVProgressHUD.dismiss()
        }

    }
}
