






#import "LoseBufferView.h"
#import "FactBasicManager.h"
#import "MixSnowBits.h"
#import "Masonry.h"

@interface LoseBufferView ()

@property (nonatomic, strong) UIView *manAreaMouthBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *exceededExtentsStripPrefixedIssuer;
@property (nonatomic, strong) UILabel *exceedsLabel;
@end

@implementation LoseBufferView


static LoseBufferView *invitedCenterView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self trustView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self trustView];
    }
    return self;
}
- (void)trustView {
    
    
    self.manAreaMouthBackgroundView = [UIView new];
    self.manAreaMouthBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.manAreaMouthBackgroundView.layer.cornerRadius = MixSnowBits.packRouteToo.tagsAndBegan;
    self.manAreaMouthBackgroundView.clipsToBounds = YES;
    [self addSubview:self.manAreaMouthBackgroundView];
    
    
    self.exceededExtentsStripPrefixedIssuer = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.exceededExtentsStripPrefixedIssuer.color = MixSnowBits.hallLaterColor;
    [self.manAreaMouthBackgroundView addSubview:self.exceededExtentsStripPrefixedIssuer];
    
    
    self.exceedsLabel = [[UILabel alloc] init];
    self.exceedsLabel.text = MixSnowBits.theBinAlignWax.busParameter;
    self.exceedsLabel.textColor = [UIColor whiteColor];
    self.exceedsLabel.font = [UIFont systemFontOfSize:14];
    self.exceedsLabel.numberOfLines = 0;
    self.exceedsLabel.textAlignment = NSTextAlignmentCenter;
    [self.manAreaMouthBackgroundView addSubview:self.exceedsLabel];
    
    
    [self.manAreaMouthBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(MixSnowBits.packRouteToo.ownStopHisBus, MixSnowBits.packRouteToo.ownStopHisBus));
        make.center.equalTo(self);
    }];
    
    [self.exceededExtentsStripPrefixedIssuer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(MixSnowBits.packRouteToo.tagsAndBegan);
        make.centerX.equalTo(self.manAreaMouthBackgroundView.mas_centerX);
    }];
    
    [self.exceedsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.exceededExtentsStripPrefixedIssuer.mas_bottom).offset(MixSnowBits.packRouteToo.tagsAndBegan);
        make.centerX.equalTo(self.manAreaMouthBackgroundView.mas_centerX);
        make.left.equalTo(self.manAreaMouthBackgroundView.mas_left).offset(MixSnowBits.packRouteToo.parentSlide);
        make.right.equalTo(self.manAreaMouthBackgroundView.mas_right).offset(-MixSnowBits.packRouteToo.parentSlide);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)curlDigestText:(NSString *)text {
    self.exceedsLabel.text = text;
    
    
    CGFloat pinkWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.exceedsLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[FactBasicManager shared] arcadeCupIcyWindow];
    CGFloat teacherWidth = MIN(MAX(120, pinkWidth + 2 * 8), window.bounds.size.width);
    [self.manAreaMouthBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(teacherWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)cardAgentSockWindow {
    [self exportingMenItemSolutionsCounterAnonymousText:MixSnowBits.theBinAlignWax.busParameter];
}

+ (void)exportingMenItemSolutionsCounterAnonymousText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[FactBasicManager shared] arcadeCupIcyWindow];
        
        if (!invitedCenterView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            invitedCenterView = [[LoseBufferView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            invitedCenterView.center = window.center;
        }
        if (!invitedCenterView.superview) {
            [window addSubview:invitedCenterView];
        }
        [invitedCenterView curlDigestText:text];
        [invitedCenterView startAnimating];
    });
}

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


+ (LoseBufferView *)collapsedPlanView:(UIView *)view {
    return [self collapsedPlanView:view withText:MixSnowBits.theBinAlignWax.busParameter];
}

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

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

@end
