






#import "JobSinHalfView.h"
#import "FutureDryManager.h"
#import "AffectedBus.h"
#import "Masonry.h"

@interface JobSinHalfView ()

@property (nonatomic, strong) UIView *obtainEraserBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *getPictureShareRaiseDecipher;
@property (nonatomic, strong) UILabel *icyFormLabel;
@end

@implementation JobSinHalfView


static JobSinHalfView *partnerPurpleView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self allowView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self allowView];
    }
    return self;
}
- (void)allowView {
    
    
    self.obtainEraserBackgroundView = [UIView new];
    self.obtainEraserBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.obtainEraserBackgroundView.layer.cornerRadius = 2.0;
    self.obtainEraserBackgroundView.clipsToBounds = YES;
    [self addSubview:self.obtainEraserBackgroundView];
    
    
    self.getPictureShareRaiseDecipher = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.getPictureShareRaiseDecipher.color = AffectedBus.betterWhoColor;
    [self.obtainEraserBackgroundView addSubview:self.getPictureShareRaiseDecipher];
    
    
    self.icyFormLabel = [[UILabel alloc] init];
    self.icyFormLabel.text = AffectedBus.delayOceanMale.contentDecay;
    self.icyFormLabel.textColor = [UIColor whiteColor];
    self.icyFormLabel.font = [UIFont systemFontOfSize:14];
    self.icyFormLabel.numberOfLines = 0;
    self.icyFormLabel.textAlignment = NSTextAlignmentCenter;
    [self.obtainEraserBackgroundView addSubview:self.icyFormLabel];
    
    
    [self.obtainEraserBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(AffectedBus.mixProviders.tryDriveSense, AffectedBus.mixProviders.tryDriveSense));
        make.center.equalTo(self);
    }];
    
    [self.getPictureShareRaiseDecipher mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(AffectedBus.mixProviders.bestRetImage);
        make.centerX.equalTo(self.obtainEraserBackgroundView.mas_centerX);
    }];
    
    [self.icyFormLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.getPictureShareRaiseDecipher.mas_bottom).offset(AffectedBus.mixProviders.bestRetImage);
        make.centerX.equalTo(self.obtainEraserBackgroundView.mas_centerX);
        make.left.equalTo(self.obtainEraserBackgroundView.mas_left).offset(AffectedBus.mixProviders.plugCellWas);
        make.right.equalTo(self.obtainEraserBackgroundView.mas_right).offset(-AffectedBus.mixProviders.plugCellWas);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)deepFixSixText:(NSString *)text {
    self.icyFormLabel.text = text;
    
    
    CGFloat bandWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.icyFormLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[FutureDryManager shared] stoodSawTiedWindow];
    CGFloat stepsonWidth = MIN(MAX(120, bandWidth + 2 * 8), window.bounds.size.width);
    [self.obtainEraserBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(stepsonWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)senseTempPlusWindow {
    [self clangIrishInnerDelayAfterChestText:AffectedBus.delayOceanMale.contentDecay];
}

+ (void)clangIrishInnerDelayAfterChestText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[FutureDryManager shared] stoodSawTiedWindow];
        
        if (!partnerPurpleView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            partnerPurpleView = [[JobSinHalfView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            partnerPurpleView.center = window.center;
        }
        if (!partnerPurpleView.superview) {
            [window addSubview:partnerPurpleView];
        }
        [partnerPurpleView deepFixSixText:text];
        [partnerPurpleView startAnimating];
    });
}

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


+ (JobSinHalfView *)bounceOutcomeView:(UIView *)view {
    return [self bounceOutcomeView:view withText:AffectedBus.delayOceanMale.contentDecay];
}

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

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

@end
