






#import "OnceStickyView.h"
#import "SoloSlantManager.h"
#import "HexDiscrete.h"
#import "Masonry.h"

@interface OnceStickyView ()

@property (nonatomic, strong) UIView *geometricTapBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *blobWarningFlightsPendingClient;
@property (nonatomic, strong) UILabel *ourLineLabel;
@end

@implementation OnceStickyView


static OnceStickyView *valuePrepDrawView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self cycleView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self cycleView];
    }
    return self;
}
- (void)cycleView {
    
    
    self.geometricTapBackgroundView = [UIView new];
    self.geometricTapBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.geometricTapBackgroundView.layer.cornerRadius = HexDiscrete.shelfTenSide.dueMetalLink;
    self.geometricTapBackgroundView.clipsToBounds = YES;
    [self addSubview:self.geometricTapBackgroundView];
    
    
    self.blobWarningFlightsPendingClient = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.blobWarningFlightsPendingClient.color = HexDiscrete.prominentColor;
    [self.geometricTapBackgroundView addSubview:self.blobWarningFlightsPendingClient];
    
    
    self.ourLineLabel = [[UILabel alloc] init];
    self.ourLineLabel.text = HexDiscrete.twistSheWasWin.biotinCarBut;
    self.ourLineLabel.textColor = [UIColor whiteColor];
    self.ourLineLabel.font = [UIFont systemFontOfSize:14];
    self.ourLineLabel.numberOfLines = 0;
    self.ourLineLabel.textAlignment = NSTextAlignmentCenter;
    [self.geometricTapBackgroundView addSubview:self.ourLineLabel];
    
    
    [self.geometricTapBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(HexDiscrete.shelfTenSide.penLoseSeeSee, HexDiscrete.shelfTenSide.penLoseSeeSee));
        make.center.equalTo(self);
    }];
    
    [self.blobWarningFlightsPendingClient mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(HexDiscrete.shelfTenSide.dueMetalLink);
        make.centerX.equalTo(self.geometricTapBackgroundView.mas_centerX);
    }];
    
    [self.ourLineLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.blobWarningFlightsPendingClient.mas_bottom).offset(HexDiscrete.shelfTenSide.dueMetalLink);
        make.centerX.equalTo(self.geometricTapBackgroundView.mas_centerX);
        make.left.equalTo(self.geometricTapBackgroundView.mas_left).offset(HexDiscrete.shelfTenSide.subLiterFix);
        make.right.equalTo(self.geometricTapBackgroundView.mas_right).offset(-HexDiscrete.shelfTenSide.subLiterFix);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)askFixRainText:(NSString *)text {
    self.ourLineLabel.text = text;
    
    
    CGFloat liftWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.ourLineLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[SoloSlantManager shared] foggyTiedDueWindow];
    CGFloat companyWidth = MIN(MAX(120, liftWidth + 2 * 8), window.bounds.size.width);
    [self.geometricTapBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(companyWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)mayAgeSpacingWindow {
    [self wakeHeadlineTorchServicesBuilderSpeedText:HexDiscrete.twistSheWasWin.biotinCarBut];
}

+ (void)wakeHeadlineTorchServicesBuilderSpeedText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[SoloSlantManager shared] foggyTiedDueWindow];
        
        if (!valuePrepDrawView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            valuePrepDrawView = [[OnceStickyView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            valuePrepDrawView.center = window.center;
        }
        if (!valuePrepDrawView.superview) {
            [window addSubview:valuePrepDrawView];
        }
        [valuePrepDrawView askFixRainText:text];
        [valuePrepDrawView startAnimating];
    });
}

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


+ (OnceStickyView *)oneSpousesMixView:(UIView *)view {
    return [self oneSpousesMixView:view withText:HexDiscrete.twistSheWasWin.biotinCarBut];
}

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

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

@end
