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


import Toast_Swift

let TSToastShared = TSToastTool.shared

class TSToastTool {
    static let shared = TSToastTool()
    private var activityView: UIView?

    private init() {}

    /// 显示文字提示
    func showToast(message: String, duration: TimeInterval = 2.0, in view: UIView? = nil) {
        kExecuteOnMainThread {
            WindowHelper.getCurrentWindow()?.makeToast(message, duration: duration, position: .center, style: self.defaultStyle())
        }
    }

    /// 显示加载动画
    func showLoading(in view: UIView? = nil) {
        kExecuteOnMainThread {
            self.hideLoading()
            WindowHelper.getCurrentWindow()?.makeToastActivity(.center)
        }
    }

    /// 隐藏加载动画
    func hideLoading() {
        kDelayMainShort {
            WindowHelper.getCurrentWindow()?.hideToastActivity()
        }
    }

    /// Toast 默认样式
    private func defaultStyle() -> ToastStyle {
       var style = ToastStyle()
       style.backgroundColor = UIColor.black.withAlphaComponent(0.7)
       style.messageColor = .white
       style.messageFont = UIFont.systemFont(ofSize: 14, weight: .medium)
       style.cornerRadius = 8
       return style
    }
    

    
}
