






#import "OpaqueKeyManager.h"
#import "LatePastIllSobViewController.h"
#import "SizeFactorConfig.h"

@interface OpaqueKeyManager()
@property (nonatomic, strong) NSMutableArray<UIWindow *> *worldHeartFoot;  
@property (nonatomic, strong) NSMutableArray<UIWindow *> *stormNoneRed;  
@end

@implementation OpaqueKeyManager

- (instancetype)init {
    self = [super init];
    if (self) {
        _worldHeartFoot = [NSMutableArray array];
        _stormNoneRed = [NSMutableArray array];
    }
    return self;
}

+ (instancetype)shared {
    static id shared = nil;
    static dispatch_once_t daysToken;
    dispatch_once(&daysToken, ^{
        shared = [[super alloc] init];
    });
    return shared;
}


- (UIWindow *)sleepBreakWindow {
    UIWindow *blockWindow = nil;
    
    if (@available(iOS 13.0, *)) {
        
        NSSet<UIScene *> *connectedScenes = [UIApplication sharedApplication].connectedScenes;
        for (UIScene *scene in connectedScenes) {
            
            if (scene.activationState == UISceneActivationStateForegroundActive &&
                [scene isKindOfClass:[UIWindowScene class]]) {
                
                UIWindowScene *windowScene = (UIWindowScene *)scene;
                
                if (windowScene.windows.count > 0) {
                    blockWindow = windowScene.windows.firstObject;
                }
                break;
            }
        }
    } else {
        
        NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
        if (windows.count > 0) {
            blockWindow = windows.firstObject;
        }
    }
    
    
    if (!blockWindow) {
        NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
        if (windows.count > 0) {
            blockWindow = windows.firstObject;
        }
    }
    
    return blockWindow;
}


- (UIWindow *)onlineResignWindow {
    
    UIWindow *pubMoleWindow = nil;
    
    if (@available(iOS 13.0, *)) {
        NSSet<UIScene *> *connectedScenes = [UIApplication sharedApplication].connectedScenes;
        for (UIScene *scene in connectedScenes) {
            if (scene.activationState == UISceneActivationStateForegroundActive &&
                [scene isKindOfClass:[UIWindowScene class]]) {
                UIWindowScene *windowScene = (UIWindowScene *)scene;
                
                
                if (@available(iOS 15.0, *)) {
                    pubMoleWindow = windowScene.keyWindow;
                }
                
                else {
                    for (UIWindow *window in windowScene.windows) {
                        if (window.isKeyWindow) {
                            pubMoleWindow = window;
                            break;
                        }
                    }
                }
                break;
            }
        }
    } else {
        
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        pubMoleWindow = [UIApplication sharedApplication].keyWindow;
#pragma clang diagnostic pop
    }
    
    
    if (!pubMoleWindow) {
        NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
        for (UIWindow *window in windows) {
            if (window.isKeyWindow) {
                pubMoleWindow = window;
                break;
            }
        }
    }
    
    return pubMoleWindow;
}


- (void)abortKinBagNearItsFeetOtherViewController:(UIViewController *)dryHex{
    dispatch_async(dispatch_get_main_queue(), ^{
        
        if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
            
            UIWindow *twoWindow = [self friendsFoodOwnershipSliceSlightParse:dryHex];
            
            
            [self userMenGatewaysRainTeamService:twoWindow];
            
            [self.worldHeartFoot addObject:twoWindow];
        } else {
            
            __weak typeof(self) weakSelf = self;
            
            __block __weak id car = nil;
            
            car = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification
                                                                       object:nil
                                                                        queue:[NSOperationQueue mainQueue]
                                                                   usingBlock:^(NSNotification *note) {
                
                [[NSNotificationCenter defaultCenter] removeObserver:car];
                [weakSelf abortKinBagNearItsFeetOtherViewController:dryHex];
            }];
        }
    });
}

- (void)eulerAllPreventMatchIntentPlanarViewController:(UIViewController *)dryHex {
    dispatch_async(dispatch_get_main_queue(), ^{
        if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
            [self recentlyPotentialMandarinYouSenseLoadPanel:dryHex];
        } else {
            
            __weak typeof(self) weakSelf = self;
            
            __block __weak id car = nil;
            
            car = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification
                                                                       object:nil
                                                                        queue:[NSOperationQueue mainQueue]
                                                                   usingBlock:^(NSNotification *note) {
                
                [[NSNotificationCenter defaultCenter] removeObserver:car];
                
                [weakSelf recentlyPotentialMandarinYouSenseLoadPanel:dryHex];
            }];
        }
    });
}

- (void)actualBitMandarinWinCloudyDegradedView:(UIView *)view {
    dispatch_async(dispatch_get_main_queue(), ^{
        if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
            [self recentlyPotentialMandarinYouSenseLoadPanel:view];
        } else {
            
            __weak typeof(self) weakSelf = self;
            
            __block __weak id car = nil;
            
            car = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification
                                                                       object:nil
                                                                        queue:[NSOperationQueue mainQueue]
                                                                   usingBlock:^(NSNotification *note) {
                
                [[NSNotificationCenter defaultCenter] removeObserver:car];
                
                [weakSelf recentlyPotentialMandarinYouSenseLoadPanel:view];
            }];
        }
    });
}

- (void)recentlyPotentialMandarinYouSenseLoadPanel:(id)object {
    UIViewController *dryHex = nil;
    
        
    if ([object isKindOfClass:[UIViewController class]]) {
        dryHex = object;
    }
    
    if ([object isKindOfClass:[UIView class]]) {
        dryHex = [LatePastIllSobViewController new];
        dryHex.view = object;
    }
    
    
    UIWindow *twoWindow = [self friendsFoodOwnershipSliceSlightParse:dryHex];
    
    
    [self userMenGatewaysRainTeamService:twoWindow];
    
    
    [self.stormNoneRed addObject:twoWindow];
}

- (void)slightMapPubPerfusionGermanResources:(NSNotification *)note {
    
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:UIApplicationDidBecomeActiveNotification
                                                  object:nil];
    [self actualBitMandarinWinCloudyDegradedView:note.object];
}

- (void)overMatchPinWindow {
    [self cityInjectionHostingIndentAvailWindow];
}

- (void)cityInjectionHostingIndentAvailWindow {
    dispatch_async(dispatch_get_main_queue(), ^{
        if (self.stormNoneRed.count == 0) return;

        
        UIWindow *taskWindow = [self.stormNoneRed lastObject];
        [self.stormNoneRed removeLastObject];

        
        if (taskWindow.isKeyWindow) {
            [self groupLawSobPinWindow];
        }

        
        taskWindow.hidden = YES;
        
        
        for (UIView *foodOff in [taskWindow.subviews copy]) {
            [foodOff removeFromSuperview];
        }
        
        
        taskWindow.rootViewController = nil;
        
        
        [CATransaction flush];
        
        
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
    });
}

- (void)periodScreenYearsExposeWatchedExtendingViewController:(UIViewController *)rootViewController {
    dispatch_async(dispatch_get_main_queue(), ^{
        NSEnumerator *canonHourRouterMinuteAzimuth = [self.stormNoneRed reverseObjectEnumerator];
        UIWindow *window = nil;
        
        
        while ((window = [canonHourRouterMinuteAzimuth nextObject])) {
            if (window.rootViewController == rootViewController) {
                
                if (window.isKeyWindow) {
                    [self groupLawSobPinWindow];
                }
                
                
                window.hidden = YES;
                
                
                for (UIView *foodOff in [window.subviews copy]) {
                    [foodOff removeFromSuperview];
                }
                
                
                window.rootViewController = nil;
                
                [self.stormNoneRed removeObject:window];
                
                
                [CATransaction flush];
                
                
                [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
                
                
                canonHourRouterMinuteAzimuth = [self.stormNoneRed reverseObjectEnumerator];
            }
        }
    });
}

- (void)enablingDaysStormSharpenSegmentedDark {
    dispatch_async(dispatch_get_main_queue(), ^{
        
        for (UIWindow *window in [self.stormNoneRed reverseObjectEnumerator]) {
            if (window.isKeyWindow) {
                [self groupLawSobPinWindow];
            }
            window.hidden = YES;
            
            
            for (UIView *foodOff in [window.subviews copy]) {
                [foodOff removeFromSuperview];
            }
            
            
            window.rootViewController = nil;
        }
        
        
        [self.stormNoneRed removeAllObjects];
        
        
        [CATransaction flush];
        
        
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.05]];
    });
}

- (void)applyNotBasicGeometricChlorideProvideShake:(void(^)(void))completion {
    
    if (self.stormNoneRed.count == 0) {
        if (completion) {
            dispatch_async(dispatch_get_main_queue(), ^{
                completion();
            });
        }
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        NSArray *reductionButPetabytesTransposeRational = [self.stormNoneRed copy];
        for (UIWindow *window in reductionButPetabytesTransposeRational) {
            if (window.isKeyWindow) {
                [self groupLawSobPinWindow];
            }
            window.hidden = YES;
            
            
            for (UIView *foodOff in [window.subviews copy]) {
                [foodOff removeFromSuperview];
            }
            
            
            window.rootViewController = nil;
        }
        
        
        [self.stormNoneRed removeAllObjects];
        
        
        [CATransaction flush];
        
        
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
        
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            if (completion) {
                completion();
            }
        });
    });
}


- (UIWindow *)friendsFoodOwnershipSliceSlightParse:(UIViewController *)dryHex {
    UIWindow *window = nil;
    
    
    if (@available(iOS 13.0, *)) {
        for (UIScene *scene in [UIApplication sharedApplication].connectedScenes) {
            if (scene.activationState == UISceneActivationStateForegroundActive &&
                [scene isKindOfClass:[UIWindowScene class]]) {
                window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene *)scene];
                break;
            }
        }
    }
    
    
    if (!window) {
        window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    }
    
    
    window.backgroundColor = [UIColor clearColor];
    window.rootViewController = dryHex;
    return window;
}

- (void)userMenGatewaysRainTeamService:(UIWindow *)window {
    

    window.windowLevel = UIWindowLevelStatusBar + 100;
    [window makeKeyAndVisible];
}


- (void)groupLawSobPinWindow {
    UIWindow *dragWindow = [self runAccountsWindow];
    [dragWindow makeKeyWindow];
    if (!dragWindow.isKeyWindow) {
        [dragWindow becomeKeyWindow];
    }
}

- (UIWindow *)runAccountsWindow {
    __block UIWindow *dragWindow = nil;
    
    
    if (@available(iOS 13.0, *)) {
        NSArray<UIWindowScene *> *malteseHeavy = [self requireRenewLongerHandlesFailing];
        [malteseHeavy enumerateObjectsUsingBlock:^(UIWindowScene * _Nonnull scene, NSUInteger idx, BOOL * _Nonnull stop) {
            
            if (@available(iOS 15.0, *)) {
                dragWindow = scene.keyWindow;
            }
            
            if (!dragWindow) {
                dragWindow = [scene.windows firstObject];
            }
            if (dragWindow) *stop = YES;
        }];
    }
    
    else {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        dragWindow = [UIApplication sharedApplication].keyWindow;
#pragma clang diagnostic pop
    }
    
    
    if (!dragWindow) {
        dragWindow = [UIApplication sharedApplication].windows.firstObject;
    }
    
    return dragWindow;
}

- (NSArray<UIWindowScene *> *)requireRenewLongerHandlesFailing {
    NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(UIScene * _Nullable scene, NSDictionary<NSString *,id> * _Nullable bindings) {
        return scene.activationState == UISceneActivationStateForegroundActive;
    }];
    return [[UIApplication sharedApplication].connectedScenes filteredSetUsingPredicate:predicate].allObjects;
}


- (UIWindow *)sumWindow {
    return [self.stormNoneRed lastObject];
}

- (NSInteger)quotesCount {
    return self.stormNoneRed.count;
}


@end
