//
//  TSToastTool.swift
//  TSLiveWallpaper
//
//  Created by 100Years on 2024/12/20.
//

import SVProgressHUD

public let TSToastShared = TSToastTool.shared

open class TSToastTool {
    public static let shared = TSToastTool()
    
    private init() {
//        SVProgressHUD.swizzleMethods()
//        如果您想要堆叠 HUD，您可以使用以下方法平衡每个节目通话：
//        [SVProgressHUD popActivity];
        SVProgressHUD.setDefaultStyle(.dark)
        SVProgressHUD.setDefaultAnimationType(.native)
        SVProgressHUD.setDefaultMaskType(.clear)
        SVProgressHUD.setMinimumSize(CGSize(width: 100, height: 100))
        SVProgressHUD.setCornerRadius(16.0)
        SVProgressHUD.setBackgroundColor("#000000".uiColor.withAlphaComponent(0.8))
        SVProgressHUD.setForegroundColor(.white)
        SVProgressHUD.setMinimumDismissTimeInterval(3.0)
//        SVProgressHUD.setInfoImage(UIImage())
//        SVProgressHUD.setImageViewSize(CGSize.zero)

    }
    
    
    public func setUIContent(font:UIFont? = nil,infoImage:UIImage? = nil) {
        if let font = font {
            SVProgressHUD.setFont(font)
        }
        
        if let infoImage = infoImage {
            SVProgressHUD.setInfoImage(infoImage)
        }
        
    }

    /// 显示文字提示
    public func showToast(text: String?, duration: TimeInterval = 3.0,containerView:UIView? = nil) {
        if let text = text {
            if text.count == 0 {
                return
            }
            kMainAsync {
                if let containerView = containerView {
                    SVProgressHUD.setContainerView(containerView)
                }else if let window = WindowHelper.getCurrentWindow() {
                    SVProgressHUD.setContainerView(window)
                }
                SVProgressHUD.setDefaultMaskType(.none)
                SVProgressHUD.showInfo(withStatus: text)
            }
        }
    }
    

    /// 显示加载动画
    public func showLoading(text:String? = nil,containerView:UIView? = WindowHelper.getCurrentWindow()) {
        kMainAsync {
            SVProgressHUD.setDefaultMaskType(.clear)
            SVProgressHUD.setContainerView(containerView)
            SVProgressHUD.show(withStatus: text)
        }
    }

    /// 隐藏加载动画
    public func hideLoading() {
        kMainAsync {
            SVProgressHUD.dismiss()
        }
    }
    
    /// 显示进度提示
    public func showProgress(progress:Float, status: String?,containerView:UIView?) {
        kMainAsync {
            SVProgressHUD.setDefaultMaskType(.clear)
            SVProgressHUD.setContainerView(containerView)
            SVProgressHUD.showProgress(progress, status: status)
        }
    }
}


public func kShowToastDataMissing(){
    TSToastShared.showToast(text: "Data missing")
}
