






#import "BuilderBoxView.h"
#import "CombiningManager.h"
#import "ApplyToggle.h"
#import "Masonry.h"

@interface BuilderBoxView ()

@property (nonatomic, strong) UIView *sparseBitKeyBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *playMinAuxiliaryTwoInternet;
@property (nonatomic, strong) UILabel *segmentLabel;
@end

@implementation BuilderBoxView


static BuilderBoxView *faxInversePutView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self issueView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self issueView];
    }
    return self;
}
- (void)issueView {
    
    
    self.sparseBitKeyBackgroundView = [UIView new];
    self.sparseBitKeyBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.sparseBitKeyBackgroundView.layer.cornerRadius = ApplyToggle.findSwipeOur.twoMenuShare;
    self.sparseBitKeyBackgroundView.clipsToBounds = YES;
    [self addSubview:self.sparseBitKeyBackgroundView];
    
    
    self.playMinAuxiliaryTwoInternet = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.playMinAuxiliaryTwoInternet.color = ApplyToggle.dueMethodColor;
    [self.sparseBitKeyBackgroundView addSubview:self.playMinAuxiliaryTwoInternet];
    
    
    self.segmentLabel = [[UILabel alloc] init];
    self.segmentLabel.text = ApplyToggle.subDayEventDay.outHungarian;
    self.segmentLabel.textColor = [UIColor whiteColor];
    self.segmentLabel.font = [UIFont systemFontOfSize:14];
    self.segmentLabel.numberOfLines = 0;
    self.segmentLabel.textAlignment = NSTextAlignmentCenter;
    [self.sparseBitKeyBackgroundView addSubview:self.segmentLabel];
    
    
    [self.sparseBitKeyBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(ApplyToggle.findSwipeOur.affiliateFace, ApplyToggle.findSwipeOur.affiliateFace));
        make.center.equalTo(self);
    }];
    
    [self.playMinAuxiliaryTwoInternet mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ApplyToggle.findSwipeOur.twoMenuShare);
        make.centerX.equalTo(self.sparseBitKeyBackgroundView.mas_centerX);
    }];
    
    [self.segmentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.playMinAuxiliaryTwoInternet.mas_bottom).offset(ApplyToggle.findSwipeOur.twoMenuShare);
        make.centerX.equalTo(self.sparseBitKeyBackgroundView.mas_centerX);
        make.left.equalTo(self.sparseBitKeyBackgroundView.mas_left).offset(ApplyToggle.findSwipeOur.downhillToo);
        make.right.equalTo(self.sparseBitKeyBackgroundView.mas_right).offset(-ApplyToggle.findSwipeOur.downhillToo);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)undoEarDayText:(NSString *)text {
    self.segmentLabel.text = text;
    
    
    CGFloat flipWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.segmentLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[CombiningManager shared] ownNegotiateWindow];
    CGFloat bagFactWidth = MIN(MAX(120, flipWidth + 2 * 8), window.bounds.size.width);
    [self.sparseBitKeyBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(bagFactWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)lessPanButBagWindow {
    [self sexTrialCustomFocusesFactClearText:ApplyToggle.subDayEventDay.outHungarian];
}

+ (void)sexTrialCustomFocusesFactClearText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[CombiningManager shared] ownNegotiateWindow];
        
        if (!faxInversePutView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            faxInversePutView = [[BuilderBoxView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            faxInversePutView.center = window.center;
        }
        if (!faxInversePutView.superview) {
            [window addSubview:faxInversePutView];
        }
        [faxInversePutView undoEarDayText:text];
        [faxInversePutView startAnimating];
    });
}

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


+ (BuilderBoxView *)maleRedManSunView:(UIView *)view {
    return [self maleRedManSunView:view withText:ApplyToggle.subDayEventDay.outHungarian];
}

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

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

@end
