






#import "AllSunLoopView.h"
#import "ThickFlagManager.h"
#import "BigAddition.h"
#import "Masonry.h"

@interface AllSunLoopView ()

@property (nonatomic, strong) UIView *realmHasNameBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *emailMagentaStretchPrepBusy;
@property (nonatomic, strong) UILabel *infoTapLabel;
@end

@implementation AllSunLoopView


static AllSunLoopView *panLibraryTipView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self clickView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self clickView];
    }
    return self;
}
- (void)clickView {
    
    
    self.realmHasNameBackgroundView = [UIView new];
    self.realmHasNameBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.realmHasNameBackgroundView.layer.cornerRadius = 2.0;
    self.realmHasNameBackgroundView.clipsToBounds = YES;
    [self addSubview:self.realmHasNameBackgroundView];
    
    
    self.emailMagentaStretchPrepBusy = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.emailMagentaStretchPrepBusy.color = BigAddition.portHumanColor;
    [self.realmHasNameBackgroundView addSubview:self.emailMagentaStretchPrepBusy];
    
    
    self.infoTapLabel = [[UILabel alloc] init];
    self.infoTapLabel.text = BigAddition.lateTapLineAll.floorGetCard;
    self.infoTapLabel.textColor = [UIColor whiteColor];
    self.infoTapLabel.font = [UIFont systemFontOfSize:14];
    self.infoTapLabel.numberOfLines = 0;
    self.infoTapLabel.textAlignment = NSTextAlignmentCenter;
    [self.realmHasNameBackgroundView addSubview:self.infoTapLabel];
    
    
    [self.realmHasNameBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(BigAddition.noiseFactMen.needStatement, BigAddition.noiseFactMen.needStatement));
        make.center.equalTo(self);
    }];
    
    [self.emailMagentaStretchPrepBusy mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(BigAddition.noiseFactMen.subReadyNear);
        make.centerX.equalTo(self.realmHasNameBackgroundView.mas_centerX);
    }];
    
    [self.infoTapLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.emailMagentaStretchPrepBusy.mas_bottom).offset(BigAddition.noiseFactMen.subReadyNear);
        make.centerX.equalTo(self.realmHasNameBackgroundView.mas_centerX);
        make.left.equalTo(self.realmHasNameBackgroundView.mas_left).offset(BigAddition.noiseFactMen.tempRetMenu);
        make.right.equalTo(self.realmHasNameBackgroundView.mas_right).offset(-BigAddition.noiseFactMen.tempRetMenu);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)sheToneRetText:(NSString *)text {
    self.infoTapLabel.text = text;
    
    
    CGFloat markWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.infoTapLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[ThickFlagManager shared] samplerAdobeWindow];
    CGFloat poolAskWidth = MIN(MAX(120, markWidth + 2 * 8), window.bounds.size.width);
    [self.realmHasNameBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(poolAskWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)yetBusNowForkWindow {
    [self climbedSpaAgeRaceLabelNotifiedText:BigAddition.lateTapLineAll.floorGetCard];
}

+ (void)climbedSpaAgeRaceLabelNotifiedText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[ThickFlagManager shared] samplerAdobeWindow];
        
        if (!panLibraryTipView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            panLibraryTipView = [[AllSunLoopView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            panLibraryTipView.center = window.center;
        }
        if (!panLibraryTipView.superview) {
            [window addSubview:panLibraryTipView];
        }
        [panLibraryTipView sheToneRetText:text];
        [panLibraryTipView startAnimating];
    });
}

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


+ (AllSunLoopView *)penTopSurfaceView:(UIView *)view {
    return [self penTopSurfaceView:view withText:BigAddition.lateTapLineAll.floorGetCard];
}

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

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

@end
