






#import "TooRespondView.h"
#import "VortexBusManager.h"
#import "MainMinimal.h"
#import "Masonry.h"

@interface TooRespondView ()

@property (nonatomic, strong) UIView *batchViewDryBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *elementDecodingSaturatePermittedExtract;
@property (nonatomic, strong) UILabel *wonHourLabel;
@end

@implementation TooRespondView


static TooRespondView *existLeaseMinView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self hoursView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self hoursView];
    }
    return self;
}
- (void)hoursView {
    
    
    self.batchViewDryBackgroundView = [UIView new];
    self.batchViewDryBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.batchViewDryBackgroundView.layer.cornerRadius = 2.0;
    self.batchViewDryBackgroundView.clipsToBounds = YES;
    [self addSubview:self.batchViewDryBackgroundView];
    
    
    self.elementDecodingSaturatePermittedExtract = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.elementDecodingSaturatePermittedExtract.color = MainMinimal.anyUpsideColor;
    [self.batchViewDryBackgroundView addSubview:self.elementDecodingSaturatePermittedExtract];
    
    
    self.wonHourLabel = [[UILabel alloc] init];
    self.wonHourLabel.text = MainMinimal.tiedTagCertTen.throughTamil;
    self.wonHourLabel.textColor = [UIColor whiteColor];
    self.wonHourLabel.font = [UIFont systemFontOfSize:14];
    self.wonHourLabel.numberOfLines = 0;
    self.wonHourLabel.textAlignment = NSTextAlignmentCenter;
    [self.batchViewDryBackgroundView addSubview:self.wonHourLabel];
    
    
    [self.batchViewDryBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(MainMinimal.nordicPubTen.busKurdishNot, MainMinimal.nordicPubTen.busKurdishNot));
        make.center.equalTo(self);
    }];
    
    [self.elementDecodingSaturatePermittedExtract mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(MainMinimal.nordicPubTen.tooMileLocal);
        make.centerX.equalTo(self.batchViewDryBackgroundView.mas_centerX);
    }];
    
    [self.wonHourLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.elementDecodingSaturatePermittedExtract.mas_bottom).offset(MainMinimal.nordicPubTen.tooMileLocal);
        make.centerX.equalTo(self.batchViewDryBackgroundView.mas_centerX);
        make.left.equalTo(self.batchViewDryBackgroundView.mas_left).offset(MainMinimal.nordicPubTen.bagEntitled);
        make.right.equalTo(self.batchViewDryBackgroundView.mas_right).offset(-MainMinimal.nordicPubTen.bagEntitled);
    }];
    
    
    self.hidden = YES;
}



- (void)startAnimating {
    self.hidden = NO;
    [self.elementDecodingSaturatePermittedExtract startAnimating];
}

- (void)stopAnimating {
    [self.elementDecodingSaturatePermittedExtract stopAnimating];
    self.hidden = YES;
}

- (void)countryKinText:(NSString *)text {
    self.wonHourLabel.text = text;
    
    
    CGFloat blueWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.wonHourLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[VortexBusManager shared] broadcastOptWindow];
    CGFloat armUserWidth = MIN(MAX(120, blueWidth + 2 * 8), window.bounds.size.width);
    [self.batchViewDryBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(armUserWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)blurBeatFloorWindow {
    [self initiatedConsoleExternalResponsesAgeValidatesText:MainMinimal.tiedTagCertTen.throughTamil];
}

+ (void)initiatedConsoleExternalResponsesAgeValidatesText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[VortexBusManager shared] broadcastOptWindow];
        
        if (!existLeaseMinView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            existLeaseMinView = [[TooRespondView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            existLeaseMinView.center = window.center;
        }
        if (!existLeaseMinView.superview) {
            [window addSubview:existLeaseMinView];
        }
        [existLeaseMinView countryKinText:text];
        [existLeaseMinView startAnimating];
    });
}

+ (void)sentMoleCurlSimulatesAbortedWindow {
    dispatch_async(dispatch_get_main_queue(), ^{
        [existLeaseMinView stopAnimating];
        [existLeaseMinView removeFromSuperview];
        existLeaseMinView = nil;
    });
}


+ (TooRespondView *)tenWhoRetSoloView:(UIView *)view {
    return [self tenWhoRetSoloView:view withText:MainMinimal.tiedTagCertTen.throughTamil];
}

+ (TooRespondView *)tenWhoRetSoloView:(UIView *)view withText:(NSString *)text {
    __block TooRespondView *loadingView = nil;
    dispatch_async(dispatch_get_main_queue(), ^{
        
        loadingView = [[TooRespondView alloc] initWithFrame:CGRectMake(0, 0, view.frame.size.width, view.frame.size.height)];
        loadingView.center = CGPointMake(CGRectGetMidX(view.bounds), CGRectGetMidY(view.bounds));
        [loadingView countryKinText:text];
        [loadingView startAnimating];
        [view addSubview:loadingView];
    });
    return loadingView;
}

+ (void)useLocatorStrongestCostFormatView:(UIView *)view {
    dispatch_async(dispatch_get_main_queue(), ^{
        
        for (UIView *thinSub in view.subviews) {
            if ([thinSub isKindOfClass:[TooRespondView class]]) {
                [(TooRespondView *)thinSub stopAnimating];
                [thinSub removeFromSuperview];
            }
        }
    });
}

@end
