






#import "BeaconMostView.h"
#import "TagsFoggyManager.h"
#import "PlayDragTap.h"
#import "Masonry.h"

@interface BeaconMostView ()

@property (nonatomic, strong) UIView *loopsRangingBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *counterGeneralSixKilogramRecovered;
@property (nonatomic, strong) UILabel *cookiesLabel;
@end

@implementation BeaconMostView


static BeaconMostView *sidebarJabberView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self spineView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self spineView];
    }
    return self;
}
- (void)spineView {
    
    
    self.loopsRangingBackgroundView = [UIView new];
    self.loopsRangingBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.loopsRangingBackgroundView.layer.cornerRadius = 2.0;
    self.loopsRangingBackgroundView.clipsToBounds = YES;
    [self addSubview:self.loopsRangingBackgroundView];
    
    
    self.counterGeneralSixKilogramRecovered = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.counterGeneralSixKilogramRecovered.color = PlayDragTap.realUpperColor;
    [self.loopsRangingBackgroundView addSubview:self.counterGeneralSixKilogramRecovered];
    
    
    self.cookiesLabel = [[UILabel alloc] init];
    self.cookiesLabel.text = PlayDragTap.andSugarSawBar.tabVendorTen;
    self.cookiesLabel.textColor = [UIColor whiteColor];
    self.cookiesLabel.font = [UIFont systemFontOfSize:14];
    self.cookiesLabel.numberOfLines = 0;
    self.cookiesLabel.textAlignment = NSTextAlignmentCenter;
    [self.loopsRangingBackgroundView addSubview:self.cookiesLabel];
    
    
    [self.loopsRangingBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(PlayDragTap.popHandshake.changedSecond, PlayDragTap.popHandshake.changedSecond));
        make.center.equalTo(self);
    }];
    
    [self.counterGeneralSixKilogramRecovered mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(PlayDragTap.popHandshake.summaryMiles);
        make.centerX.equalTo(self.loopsRangingBackgroundView.mas_centerX);
    }];
    
    [self.cookiesLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.counterGeneralSixKilogramRecovered.mas_bottom).offset(PlayDragTap.popHandshake.summaryMiles);
        make.centerX.equalTo(self.loopsRangingBackgroundView.mas_centerX);
        make.left.equalTo(self.loopsRangingBackgroundView.mas_left).offset(PlayDragTap.popHandshake.hailTrusted);
        make.right.equalTo(self.loopsRangingBackgroundView.mas_right).offset(-PlayDragTap.popHandshake.hailTrusted);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)rhythmTextText:(NSString *)text {
    self.cookiesLabel.text = text;
    
    
    CGFloat snapWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.cookiesLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[TagsFoggyManager shared] armCorrectedWindow];
    CGFloat askHashWidth = MIN(MAX(120, snapWidth + 2 * 8), window.bounds.size.width);
    [self.loopsRangingBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(askHashWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)askMaleYouNapWindow {
    [self olympusCapBarsRetrieveRebuildNumericText:PlayDragTap.andSugarSawBar.tabVendorTen];
}

+ (void)olympusCapBarsRetrieveRebuildNumericText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[TagsFoggyManager shared] armCorrectedWindow];
        
        if (!sidebarJabberView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            sidebarJabberView = [[BeaconMostView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            sidebarJabberView.center = window.center;
        }
        if (!sidebarJabberView.superview) {
            [window addSubview:sidebarJabberView];
        }
        [sidebarJabberView rhythmTextText:text];
        [sidebarJabberView startAnimating];
    });
}

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


+ (BeaconMostView *)sawBringStaleView:(UIView *)view {
    return [self sawBringStaleView:view withText:PlayDragTap.andSugarSawBar.tabVendorTen];
}

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

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

@end
