






#import "PlayKernelView.h"
#import "DigitSongManager.h"
#import "ZipRestThat.h"
#import "Masonry.h"

@interface PlayKernelView ()

@property (nonatomic, strong) UIView *conductorFaxBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *currencyStreamOnceCanWon;
@property (nonatomic, strong) UILabel *doneArtLabel;
@end

@implementation PlayKernelView


static PlayKernelView *findEarZipDidView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self clickView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self clickView];
    }
    return self;
}
- (void)clickView {
    
    
    self.conductorFaxBackgroundView = [UIView new];
    self.conductorFaxBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.conductorFaxBackgroundView.layer.cornerRadius = 2.0;
    self.conductorFaxBackgroundView.clipsToBounds = YES;
    [self addSubview:self.conductorFaxBackgroundView];
    
    
    self.currencyStreamOnceCanWon = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.currencyStreamOnceCanWon.color = ZipRestThat.focalFadeColor;
    [self.conductorFaxBackgroundView addSubview:self.currencyStreamOnceCanWon];
    
    
    self.doneArtLabel = [[UILabel alloc] init];
    self.doneArtLabel.text = ZipRestThat.useCatAliveLow.midAlternate;
    self.doneArtLabel.textColor = [UIColor whiteColor];
    self.doneArtLabel.font = [UIFont systemFontOfSize:14];
    self.doneArtLabel.numberOfLines = 0;
    self.doneArtLabel.textAlignment = NSTextAlignmentCenter;
    [self.conductorFaxBackgroundView addSubview:self.doneArtLabel];
    
    
    [self.conductorFaxBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(ZipRestThat.heartHowLead.netAnySendTwo, ZipRestThat.heartHowLead.netAnySendTwo));
        make.center.equalTo(self);
    }];
    
    [self.currencyStreamOnceCanWon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ZipRestThat.heartHowLead.warningAlarm);
        make.centerX.equalTo(self.conductorFaxBackgroundView.mas_centerX);
    }];
    
    [self.doneArtLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.currencyStreamOnceCanWon.mas_bottom).offset(ZipRestThat.heartHowLead.warningAlarm);
        make.centerX.equalTo(self.conductorFaxBackgroundView.mas_centerX);
        make.left.equalTo(self.conductorFaxBackgroundView.mas_left).offset(ZipRestThat.heartHowLead.optBurstLaw);
        make.right.equalTo(self.conductorFaxBackgroundView.mas_right).offset(-ZipRestThat.heartHowLead.optBurstLaw);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)fiveUplinkText:(NSString *)text {
    self.doneArtLabel.text = text;
    
    
    CGFloat warpWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.doneArtLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[DigitSongManager shared] irregularHerWindow];
    CGFloat dueMostWidth = MIN(MAX(120, warpWidth + 2 * 8), window.bounds.size.width);
    [self.conductorFaxBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(dueMostWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)shotOrderSlabWindow {
    [self flushSearchAmountItsBandBalanceText:ZipRestThat.useCatAliveLow.midAlternate];
}

+ (void)flushSearchAmountItsBandBalanceText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[DigitSongManager shared] irregularHerWindow];
        
        if (!findEarZipDidView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            findEarZipDidView = [[PlayKernelView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            findEarZipDidView.center = window.center;
        }
        if (!findEarZipDidView.superview) {
            [window addSubview:findEarZipDidView];
        }
        [findEarZipDidView fiveUplinkText:text];
        [findEarZipDidView startAnimating];
    });
}

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


+ (PlayKernelView *)millFlatUnifyView:(UIView *)view {
    return [self millFlatUnifyView:view withText:ZipRestThat.useCatAliveLow.midAlternate];
}

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

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

@end
