






#import "IllegalRedView.h"
#import "PopParserManager.h"
#import "RuleListCut.h"
#import "Masonry.h"

@interface IllegalRedView ()

@property (nonatomic, strong) UIView *unlimitedWinBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *wirelessFractionsFinderSortingYet;
@property (nonatomic, strong) UILabel *hexJumpLabel;
@end

@implementation IllegalRedView


static IllegalRedView *serifStopJoinView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self givenView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self givenView];
    }
    return self;
}
- (void)givenView {
    
    
    self.unlimitedWinBackgroundView = [UIView new];
    self.unlimitedWinBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.unlimitedWinBackgroundView.layer.cornerRadius = RuleListCut.coloredDraft.malteseClamp;
    self.unlimitedWinBackgroundView.clipsToBounds = YES;
    [self addSubview:self.unlimitedWinBackgroundView];
    
    
    self.wirelessFractionsFinderSortingYet = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.wirelessFractionsFinderSortingYet.color = RuleListCut.slopeLockColor;
    [self.unlimitedWinBackgroundView addSubview:self.wirelessFractionsFinderSortingYet];
    
    
    self.hexJumpLabel = [[UILabel alloc] init];
    self.hexJumpLabel.text = RuleListCut.costSonKnowKit.playSonLossy;
    self.hexJumpLabel.textColor = [UIColor whiteColor];
    self.hexJumpLabel.font = [UIFont systemFontOfSize:14];
    self.hexJumpLabel.numberOfLines = 0;
    self.hexJumpLabel.textAlignment = NSTextAlignmentCenter;
    [self.unlimitedWinBackgroundView addSubview:self.hexJumpLabel];
    
    
    [self.unlimitedWinBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(RuleListCut.coloredDraft.howHaveBoxPut, RuleListCut.coloredDraft.howHaveBoxPut));
        make.center.equalTo(self);
    }];
    
    [self.wirelessFractionsFinderSortingYet mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(RuleListCut.coloredDraft.malteseClamp);
        make.centerX.equalTo(self.unlimitedWinBackgroundView.mas_centerX);
    }];
    
    [self.hexJumpLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.wirelessFractionsFinderSortingYet.mas_bottom).offset(RuleListCut.coloredDraft.malteseClamp);
        make.centerX.equalTo(self.unlimitedWinBackgroundView.mas_centerX);
        make.left.equalTo(self.unlimitedWinBackgroundView.mas_left).offset(RuleListCut.coloredDraft.asleepScene);
        make.right.equalTo(self.unlimitedWinBackgroundView.mas_right).offset(-RuleListCut.coloredDraft.asleepScene);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)editorWarpText:(NSString *)text {
    self.hexJumpLabel.text = text;
    
    
    CGFloat maskWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.hexJumpLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[PopParserManager shared] draftEarBookWindow];
    CGFloat rawDownWidth = MIN(MAX(120, maskWidth + 2 * 8), window.bounds.size.width);
    [self.unlimitedWinBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(rawDownWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)limitHandoverWindow {
    [self shipmentLocalesRankedGloballyCancelsReminderText:RuleListCut.costSonKnowKit.playSonLossy];
}

+ (void)shipmentLocalesRankedGloballyCancelsReminderText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[PopParserManager shared] draftEarBookWindow];
        
        if (!serifStopJoinView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            serifStopJoinView = [[IllegalRedView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            serifStopJoinView.center = window.center;
        }
        if (!serifStopJoinView.superview) {
            [window addSubview:serifStopJoinView];
        }
        [serifStopJoinView editorWarpText:text];
        [serifStopJoinView startAnimating];
    });
}

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


+ (IllegalRedView *)winSuccessDayView:(UIView *)view {
    return [self winSuccessDayView:view withText:RuleListCut.costSonKnowKit.playSonLossy];
}

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

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

@end
