






#import "TorchVeryManager.h"
#import "FeatWidgetPathViewController.h"
#import "BusCityWonConfig.h"

@interface TorchVeryManager()
@property (nonatomic, strong) NSMutableArray<UIWindow *> *breakingFamily;  
@property (nonatomic, strong) NSMutableArray<UIWindow *> *phraseLogFat;  
@end

@implementation TorchVeryManager

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

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


- (UIWindow *)friendsSobWindow {
    UIWindow *frontWindow = 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) {
                    frontWindow = windowScene.windows.firstObject;
                }
                break;
            }
        }
    } else {
        
        NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
        if (windows.count > 0) {
            frontWindow = windows.firstObject;
        }
    }
    
    
    if (!frontWindow) {
        NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
        if (windows.count > 0) {
            frontWindow = windows.firstObject;
        }
    }
    
    return frontWindow;
}


- (UIWindow *)boostPutPoloWindow {
    
    UIWindow *listAnyWindow = 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, *)) {
                    listAnyWindow = windowScene.keyWindow;
                }
                
                else {
                    for (UIWindow *window in windowScene.windows) {
                        if (window.isKeyWindow) {
                            listAnyWindow = window;
                            break;
                        }
                    }
                }
                break;
            }
        }
    } else {
        
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
        listAnyWindow = [UIApplication sharedApplication].keyWindow;
#pragma clang diagnostic pop
    }
    
    
    if (!listAnyWindow) {
        NSArray<UIWindow *> *windows = [UIApplication sharedApplication].windows;
        for (UIWindow *window in windows) {
            if (window.isKeyWindow) {
                listAnyWindow = window;
                break;
            }
        }
    }
    
    return listAnyWindow;
}


- (void)parentalCriteriaAppearingFontNumberLinearChannelViewController:(UIViewController *)icyDue{
    dispatch_async(dispatch_get_main_queue(), ^{
        
        if ([UIApplication sharedApplication].applicationState == UIApplicationStateActive) {
            
            UIWindow *didWindow = [self controlLimitBagCameraCanAmharic:icyDue];
            
            
            [self noteRebusTryScopeRomanianResolved:didWindow];
            
            [self.breakingFamily addObject:didWindow];
        } else {
            
            __weak typeof(self) weakSelf = self;
            
            __block __weak id fax = nil;
            
            fax = [[NSNotificationCenter defaultCenter] addObserverForName:UIApplicationDidBecomeActiveNotification
                                                                       object:nil
                                                                        queue:[NSOperationQueue mainQueue]
                                                                   usingBlock:^(NSNotification *note) {
                
                [[NSNotificationCenter defaultCenter] removeObserver:fax];
                [weakSelf parentalCriteriaAppearingFontNumberLinearChannelViewController:icyDue];
            }];
        }
    });
}

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

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

- (void)shearYardMagnesiumExtrasElderHeapWeekly:(id)object {
    UIViewController *icyDue = nil;
    
        
    if ([object isKindOfClass:[UIViewController class]]) {
        icyDue = object;
    }
    
    if ([object isKindOfClass:[UIView class]]) {
        icyDue = [FeatWidgetPathViewController new];
        icyDue.view = object;
    }
    
    
    UIWindow *didWindow = [self controlLimitBagCameraCanAmharic:icyDue];
    
    
    [self noteRebusTryScopeRomanianResolved:didWindow];
    
    
    [self.phraseLogFat addObject:didWindow];
}

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

- (void)redSideClockWindow {
    [self reversesMutationGivenManBoxWindow];
}

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

        
        UIWindow *needWindow = [self.phraseLogFat lastObject];
        [self.phraseLogFat removeLastObject];

        
        if (needWindow.isKeyWindow) {
            [self tenWaterKitCutWindow];
        }

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

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

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

- (void)scalingIntensityExtendsGreekPromotionThroughDetail:(void(^)(void))completion {
    
    if (self.phraseLogFat.count == 0) {
        if (completion) {
            dispatch_async(dispatch_get_main_queue(), ^{
                completion();
            });
        }
        return;
    }
    
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
        NSArray *indexModifiedCosmicShelfAre = [self.phraseLogFat copy];
        for (UIWindow *window in indexModifiedCosmicShelfAre) {
            if (window.isKeyWindow) {
                [self tenWaterKitCutWindow];
            }
            window.hidden = YES;
            
            
            for (UIView *fiveNow in [window.subviews copy]) {
                [fiveNow removeFromSuperview];
            }
            
            
            window.rootViewController = nil;
        }
        
        
        [self.phraseLogFat 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 *)controlLimitBagCameraCanAmharic:(UIViewController *)icyDue {
    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 = icyDue;
    return window;
}

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

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


- (void)tenWaterKitCutWindow {
    UIWindow *boldWindow = [self renewOutletWindow];
    [boldWindow makeKeyWindow];
    if (!boldWindow.isKeyWindow) {
        [boldWindow becomeKeyWindow];
    }
}

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

- (NSArray<UIWindowScene *> *)auditSortingPanoramasRespondsImperial {
    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 *)andWindow {
    return [self.phraseLogFat lastObject];
}

- (NSInteger)runFatCount {
    return self.phraseLogFat.count;
}


@end
