






#import "StepsonRedView.h"
#import "PerformerManager.h"
#import "RedFlexible.h"
#import "Masonry.h"

@interface StepsonRedView ()

@property (nonatomic, strong) UIView *kitRemoveAskBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *playbackContainerSubscribeQuotesVision;
@property (nonatomic, strong) UILabel *ruleSobLabel;
@end

@implementation StepsonRedView


static StepsonRedView *baseNapEarGetView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self dailyView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self dailyView];
    }
    return self;
}
- (void)dailyView {
    
    
    self.kitRemoveAskBackgroundView = [UIView new];
    self.kitRemoveAskBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.kitRemoveAskBackgroundView.layer.cornerRadius = RedFlexible.capContinued.pinchExtract;
    self.kitRemoveAskBackgroundView.clipsToBounds = YES;
    [self addSubview:self.kitRemoveAskBackgroundView];
    
    
    self.playbackContainerSubscribeQuotesVision = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.playbackContainerSubscribeQuotesVision.color = RedFlexible.northTextColor;
    [self.kitRemoveAskBackgroundView addSubview:self.playbackContainerSubscribeQuotesVision];
    
    
    self.ruleSobLabel = [[UILabel alloc] init];
    self.ruleSobLabel.text = RedFlexible.daySentFaxWill.tagsVitality;
    self.ruleSobLabel.textColor = [UIColor whiteColor];
    self.ruleSobLabel.font = [UIFont systemFontOfSize:14];
    self.ruleSobLabel.numberOfLines = 0;
    self.ruleSobLabel.textAlignment = NSTextAlignmentCenter;
    [self.kitRemoveAskBackgroundView addSubview:self.ruleSobLabel];
    
    
    [self.kitRemoveAskBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(RedFlexible.capContinued.meanIntegrate, RedFlexible.capContinued.meanIntegrate));
        make.center.equalTo(self);
    }];
    
    [self.playbackContainerSubscribeQuotesVision mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(RedFlexible.capContinued.pinchExtract);
        make.centerX.equalTo(self.kitRemoveAskBackgroundView.mas_centerX);
    }];
    
    [self.ruleSobLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.playbackContainerSubscribeQuotesVision.mas_bottom).offset(RedFlexible.capContinued.pinchExtract);
        make.centerX.equalTo(self.kitRemoveAskBackgroundView.mas_centerX);
        make.left.equalTo(self.kitRemoveAskBackgroundView.mas_left).offset(RedFlexible.capContinued.composeDone);
        make.right.equalTo(self.kitRemoveAskBackgroundView.mas_right).offset(-RedFlexible.capContinued.composeDone);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)pinPrivacyText:(NSString *)text {
    self.ruleSobLabel.text = text;
    
    
    CGFloat loadWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.ruleSobLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[PerformerManager shared] sobHandBasalWindow];
    CGFloat maxBeatWidth = MIN(MAX(120, loadWidth + 2 * 8), window.bounds.size.width);
    [self.kitRemoveAskBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(maxBeatWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)ambiguousPlayWindow {
    [self identicalReportGuestGeneralLooseAlternateText:RedFlexible.daySentFaxWill.tagsVitality];
}

+ (void)identicalReportGuestGeneralLooseAlternateText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[PerformerManager shared] sobHandBasalWindow];
        
        if (!baseNapEarGetView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            baseNapEarGetView = [[StepsonRedView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            baseNapEarGetView.center = window.center;
        }
        if (!baseNapEarGetView.superview) {
            [window addSubview:baseNapEarGetView];
        }
        [baseNapEarGetView pinPrivacyText:text];
        [baseNapEarGetView startAnimating];
    });
}

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


+ (StepsonRedView *)otherPanIssueView:(UIView *)view {
    return [self otherPanIssueView:view withText:RedFlexible.daySentFaxWill.tagsVitality];
}

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

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

@end
