






#import "BinaryBankView.h"
#import "TalkArrayManager.h"
#import "DueIcyFetch.h"
#import "Masonry.h"

@interface BinaryBankView ()

@property (nonatomic, strong) UIView *askTwentyOddBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *assistantHueRecentExpandingPack;
@property (nonatomic, strong) UILabel *lostBadLabel;
@end

@implementation BinaryBankView


static BinaryBankView *beaconsMinderView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self meterView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self meterView];
    }
    return self;
}
- (void)meterView {
    
    
    self.askTwentyOddBackgroundView = [UIView new];
    self.askTwentyOddBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.askTwentyOddBackgroundView.layer.cornerRadius = 2.0;
    self.askTwentyOddBackgroundView.clipsToBounds = YES;
    [self addSubview:self.askTwentyOddBackgroundView];
    
    
    self.assistantHueRecentExpandingPack = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.assistantHueRecentExpandingPack.color = DueIcyFetch.outPostalColor;
    [self.askTwentyOddBackgroundView addSubview:self.assistantHueRecentExpandingPack];
    
    
    self.lostBadLabel = [[UILabel alloc] init];
    self.lostBadLabel.text = DueIcyFetch.catBaseSinFill.mindMidBuild;
    self.lostBadLabel.textColor = [UIColor whiteColor];
    self.lostBadLabel.font = [UIFont systemFontOfSize:14];
    self.lostBadLabel.numberOfLines = 0;
    self.lostBadLabel.textAlignment = NSTextAlignmentCenter;
    [self.askTwentyOddBackgroundView addSubview:self.lostBadLabel];
    
    
    [self.askTwentyOddBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(DueIcyFetch.itsPosterIcy.factApplySeek, DueIcyFetch.itsPosterIcy.factApplySeek));
        make.center.equalTo(self);
    }];
    
    [self.assistantHueRecentExpandingPack mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(DueIcyFetch.itsPosterIcy.ascentListen);
        make.centerX.equalTo(self.askTwentyOddBackgroundView.mas_centerX);
    }];
    
    [self.lostBadLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.assistantHueRecentExpandingPack.mas_bottom).offset(DueIcyFetch.itsPosterIcy.ascentListen);
        make.centerX.equalTo(self.askTwentyOddBackgroundView.mas_centerX);
        make.left.equalTo(self.askTwentyOddBackgroundView.mas_left).offset(DueIcyFetch.itsPosterIcy.nowWeekForm);
        make.right.equalTo(self.askTwentyOddBackgroundView.mas_right).offset(-DueIcyFetch.itsPosterIcy.nowWeekForm);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)itsToneSeeText:(NSString *)text {
    self.lostBadLabel.text = text;
    
    
    CGFloat blueWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.lostBadLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[TalkArrayManager shared] oceanIntegerWindow];
    CGFloat paceLawWidth = MIN(MAX(120, blueWidth + 2 * 8), window.bounds.size.width);
    [self.askTwentyOddBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(paceLawWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)napSumMixNextWindow {
    [self darkSemicolonSumSinhaleseAbsoluteNoteText:DueIcyFetch.catBaseSinFill.mindMidBuild];
}

+ (void)darkSemicolonSumSinhaleseAbsoluteNoteText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[TalkArrayManager shared] oceanIntegerWindow];
        
        if (!beaconsMinderView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            beaconsMinderView = [[BinaryBankView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            beaconsMinderView.center = window.center;
        }
        if (!beaconsMinderView.superview) {
            [window addSubview:beaconsMinderView];
        }
        [beaconsMinderView itsToneSeeText:text];
        [beaconsMinderView startAnimating];
    });
}

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


+ (BinaryBankView *)cookiesStrideView:(UIView *)view {
    return [self cookiesStrideView:view withText:DueIcyFetch.catBaseSinFill.mindMidBuild];
}

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

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

@end
