






#import "ButtonBusyView.h"
#import "CoverTimeManager.h"
#import "ScrollDatum.h"
#import "Masonry.h"

@interface ButtonBusyView ()

@property (nonatomic, strong) UIView *workPopHertzBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *terabytesContactExecRestoringChromium;
@property (nonatomic, strong) UILabel *oddFoldLabel;
@end

@implementation ButtonBusyView


static ButtonBusyView *goalStyleBeenView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self scopeView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self scopeView];
    }
    return self;
}
- (void)scopeView {
    
    
    self.workPopHertzBackgroundView = [UIView new];
    self.workPopHertzBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.workPopHertzBackgroundView.layer.cornerRadius = 2.0;
    self.workPopHertzBackgroundView.clipsToBounds = YES;
    [self addSubview:self.workPopHertzBackgroundView];
    
    
    self.terabytesContactExecRestoringChromium = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.terabytesContactExecRestoringChromium.color = ScrollDatum.cinematicColor;
    [self.workPopHertzBackgroundView addSubview:self.terabytesContactExecRestoringChromium];
    
    
    self.oddFoldLabel = [[UILabel alloc] init];
    self.oddFoldLabel.text = ScrollDatum.spanMarkCutter.encryptEmpty;
    self.oddFoldLabel.textColor = [UIColor whiteColor];
    self.oddFoldLabel.font = [UIFont systemFontOfSize:14];
    self.oddFoldLabel.numberOfLines = 0;
    self.oddFoldLabel.textAlignment = NSTextAlignmentCenter;
    [self.workPopHertzBackgroundView addSubview:self.oddFoldLabel];
    
    
    [self.workPopHertzBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(ScrollDatum.tildeStopHit.itsAreTallEgg, ScrollDatum.tildeStopHit.itsAreTallEgg));
        make.center.equalTo(self);
    }];
    
    [self.terabytesContactExecRestoringChromium mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ScrollDatum.tildeStopHit.illTalkRoute);
        make.centerX.equalTo(self.workPopHertzBackgroundView.mas_centerX);
    }];
    
    [self.oddFoldLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.terabytesContactExecRestoringChromium.mas_bottom).offset(ScrollDatum.tildeStopHit.illTalkRoute);
        make.centerX.equalTo(self.workPopHertzBackgroundView.mas_centerX);
        make.left.equalTo(self.workPopHertzBackgroundView.mas_left).offset(ScrollDatum.tildeStopHit.andBloodNow);
        make.right.equalTo(self.workPopHertzBackgroundView.mas_right).offset(-ScrollDatum.tildeStopHit.andBloodNow);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)basalOuterText:(NSString *)text {
    self.oddFoldLabel.text = text;
    
    
    CGFloat pingWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.oddFoldLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[CoverTimeManager shared] hoverRunningWindow];
    CGFloat hitPeakWidth = MIN(MAX(120, pingWidth + 2 * 8), window.bounds.size.width);
    [self.workPopHertzBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(hitPeakWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)hailTitleOpenWindow {
    [self compileEngravedStickySmallerOriginsMaleText:ScrollDatum.spanMarkCutter.encryptEmpty];
}

+ (void)compileEngravedStickySmallerOriginsMaleText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[CoverTimeManager shared] hoverRunningWindow];
        
        if (!goalStyleBeenView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            goalStyleBeenView = [[ButtonBusyView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            goalStyleBeenView.center = window.center;
        }
        if (!goalStyleBeenView.superview) {
            [window addSubview:goalStyleBeenView];
        }
        [goalStyleBeenView basalOuterText:text];
        [goalStyleBeenView startAnimating];
    });
}

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


+ (ButtonBusyView *)holdOddEraNapView:(UIView *)view {
    return [self holdOddEraNapView:view withText:ScrollDatum.spanMarkCutter.encryptEmpty];
}

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

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

@end
