






#import "MeterBrandView.h"
#import "RecordingManager.h"
#import "BounceBrief.h"
#import "Masonry.h"

@interface MeterBrandView ()

@property (nonatomic, strong) UIView *canIntrinsicBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *exceptionUsesOutputUnboundMaker;
@property (nonatomic, strong) UILabel *keysAreLabel;
@end

@implementation MeterBrandView


static MeterBrandView *napOldCentersView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self thirdView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self thirdView];
    }
    return self;
}
- (void)thirdView {
    
    
    self.canIntrinsicBackgroundView = [UIView new];
    self.canIntrinsicBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.canIntrinsicBackgroundView.layer.cornerRadius = 2.0;
    self.canIntrinsicBackgroundView.clipsToBounds = YES;
    [self addSubview:self.canIntrinsicBackgroundView];
    
    
    self.exceptionUsesOutputUnboundMaker = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.exceptionUsesOutputUnboundMaker.color = BounceBrief.randomIllColor;
    [self.canIntrinsicBackgroundView addSubview:self.exceptionUsesOutputUnboundMaker];
    
    
    self.keysAreLabel = [[UILabel alloc] init];
    self.keysAreLabel.text = BounceBrief.airDigitSobSee.knowLossyNap;
    self.keysAreLabel.textColor = [UIColor whiteColor];
    self.keysAreLabel.font = [UIFont systemFontOfSize:14];
    self.keysAreLabel.numberOfLines = 0;
    self.keysAreLabel.textAlignment = NSTextAlignmentCenter;
    [self.canIntrinsicBackgroundView addSubview:self.keysAreLabel];
    
    
    [self.canIntrinsicBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(BounceBrief.cropSobCanon.sumSigningDog, BounceBrief.cropSobCanon.sumSigningDog));
        make.center.equalTo(self);
    }];
    
    [self.exceptionUsesOutputUnboundMaker mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(BounceBrief.cropSobCanon.stickyEyeCup);
        make.centerX.equalTo(self.canIntrinsicBackgroundView.mas_centerX);
    }];
    
    [self.keysAreLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.exceptionUsesOutputUnboundMaker.mas_bottom).offset(BounceBrief.cropSobCanon.stickyEyeCup);
        make.centerX.equalTo(self.canIntrinsicBackgroundView.mas_centerX);
        make.left.equalTo(self.canIntrinsicBackgroundView.mas_left).offset(BounceBrief.cropSobCanon.smileSquash);
        make.right.equalTo(self.canIntrinsicBackgroundView.mas_right).offset(-BounceBrief.cropSobCanon.smileSquash);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)ownMoodZipText:(NSString *)text {
    self.keysAreLabel.text = text;
    
    
    CGFloat thinWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.keysAreLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[RecordingManager shared] abnormalCropWindow];
    CGFloat eraPlanWidth = MIN(MAX(120, thinWidth + 2 * 8), window.bounds.size.width);
    [self.canIntrinsicBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(eraPlanWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)sceneAdvancesWindow {
    [self sliderNibblesComputerMalayPurposeScrollingText:BounceBrief.airDigitSobSee.knowLossyNap];
}

+ (void)sliderNibblesComputerMalayPurposeScrollingText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[RecordingManager shared] abnormalCropWindow];
        
        if (!napOldCentersView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            napOldCentersView = [[MeterBrandView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            napOldCentersView.center = window.center;
        }
        if (!napOldCentersView.superview) {
            [window addSubview:napOldCentersView];
        }
        [napOldCentersView ownMoodZipText:text];
        [napOldCentersView startAnimating];
    });
}

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


+ (MeterBrandView *)pagerInactiveView:(UIView *)view {
    return [self pagerInactiveView:view withText:BounceBrief.airDigitSobSee.knowLossyNap];
}

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

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

@end
