






#import "CutSubjectView.h"
#import "TimeClaimManager.h"
#import "FeedSunTied.h"
#import "Masonry.h"

@interface CutSubjectView ()

@property (nonatomic, strong) UIView *advancesRedoBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *audioDisableIconSucceededFetched;
@property (nonatomic, strong) UILabel *mostBedLabel;
@end

@implementation CutSubjectView


static CutSubjectView *optPenZipPlugView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self availView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self availView];
    }
    return self;
}
- (void)availView {
    
    
    self.advancesRedoBackgroundView = [UIView new];
    self.advancesRedoBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.advancesRedoBackgroundView.layer.cornerRadius = 2.0;
    self.advancesRedoBackgroundView.clipsToBounds = YES;
    [self addSubview:self.advancesRedoBackgroundView];
    
    
    self.audioDisableIconSucceededFetched = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.audioDisableIconSucceededFetched.color = FeedSunTied.activeBigColor;
    [self.advancesRedoBackgroundView addSubview:self.audioDisableIconSucceededFetched];
    
    
    self.mostBedLabel = [[UILabel alloc] init];
    self.mostBedLabel.text = FeedSunTied.switchEnvelope.clientsBatch;
    self.mostBedLabel.textColor = [UIColor whiteColor];
    self.mostBedLabel.font = [UIFont systemFontOfSize:14];
    self.mostBedLabel.numberOfLines = 0;
    self.mostBedLabel.textAlignment = NSTextAlignmentCenter;
    [self.advancesRedoBackgroundView addSubview:self.mostBedLabel];
    
    
    [self.advancesRedoBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(FeedSunTied.rootIntegral.sumWayEpisode, FeedSunTied.rootIntegral.sumWayEpisode));
        make.center.equalTo(self);
    }];
    
    [self.audioDisableIconSucceededFetched mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(FeedSunTied.rootIntegral.siteBridging);
        make.centerX.equalTo(self.advancesRedoBackgroundView.mas_centerX);
    }];
    
    [self.mostBedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.audioDisableIconSucceededFetched.mas_bottom).offset(FeedSunTied.rootIntegral.siteBridging);
        make.centerX.equalTo(self.advancesRedoBackgroundView.mas_centerX);
        make.left.equalTo(self.advancesRedoBackgroundView.mas_left).offset(FeedSunTied.rootIntegral.sequenceHit);
        make.right.equalTo(self.advancesRedoBackgroundView.mas_right).offset(-FeedSunTied.rootIntegral.sequenceHit);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)unwindPageText:(NSString *)text {
    self.mostBedLabel.text = text;
    
    
    CGFloat leapWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.mostBedLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[TimeClaimManager shared] fourInspiredWindow];
    CGFloat textualWidth = MIN(MAX(120, leapWidth + 2 * 8), window.bounds.size.width);
    [self.advancesRedoBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(textualWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)suchAlignRoomWindow {
    [self paperExportingPostReferenceFeaturedValueText:FeedSunTied.switchEnvelope.clientsBatch];
}

+ (void)paperExportingPostReferenceFeaturedValueText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[TimeClaimManager shared] fourInspiredWindow];
        
        if (!optPenZipPlugView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            optPenZipPlugView = [[CutSubjectView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            optPenZipPlugView.center = window.center;
        }
        if (!optPenZipPlugView.superview) {
            [window addSubview:optPenZipPlugView];
        }
        [optPenZipPlugView unwindPageText:text];
        [optPenZipPlugView startAnimating];
    });
}

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


+ (CutSubjectView *)flashLeaseMaxView:(UIView *)view {
    return [self flashLeaseMaxView:view withText:FeedSunTied.switchEnvelope.clientsBatch];
}

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

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

@end
