//
//  DialogPopUpManager.swift

//
//  Created by Leon on 2025/7/14.
//

import Foundation

class DialogPopUpManager{
    public static let shared = DialogPopUpManager()
    
    lazy var toBeHandleMaskPopControllers: [BaseMaskPopDialogController] = []
    
    public func disableSubsequentPopDialogs(){
        toBeHandleMaskPopControllers.removeAll()
    }
    
    func continueDialogIfHave() {
         if !toBeHandleMaskPopControllers.isEmpty {
             var popVc = toBeHandleMaskPopControllers.first!
             // Find the dialog with the highest priority, optionally restricted to a specific class
             for vc in toBeHandleMaskPopControllers {
                 if vc.priority > popVc.priority {
                     if let onlyShowInClass = vc.onlyshowInClass, !UIWindow.getTopViewController()!.isKind(of: onlyShowInClass) {
                         // Skip if the current VC is not of the required class
                     } else {
                         popVc = vc
                     }
                 }
             }
             popVc.resetPopController()
             popVc.show()
         }
     }
     
     func delayToContinueDialog() {
         DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
             self.continueDialogIfHave()
         }
     }
}
