






#import "FetchSenseView.h"
#import "FunnelArmManager.h"
#import "MakerOldest.h"
#import "Masonry.h"

@interface FetchSenseView ()

@property (nonatomic, strong) UIView *earArrayNoteBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *visionPresetLandscapeEmptyChromatic;
@property (nonatomic, strong) UILabel *zipFontLabel;
@end

@implementation FetchSenseView


static FetchSenseView *generalSpringView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self heartView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self heartView];
    }
    return self;
}
- (void)heartView {
    
    
    self.earArrayNoteBackgroundView = [UIView new];
    self.earArrayNoteBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.earArrayNoteBackgroundView.layer.cornerRadius = 2.0;
    self.earArrayNoteBackgroundView.clipsToBounds = YES;
    [self addSubview:self.earArrayNoteBackgroundView];
    
    
    self.visionPresetLandscapeEmptyChromatic = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.visionPresetLandscapeEmptyChromatic.color = MakerOldest.caseAboutColor;
    [self.earArrayNoteBackgroundView addSubview:self.visionPresetLandscapeEmptyChromatic];
    
    
    self.zipFontLabel = [[UILabel alloc] init];
    self.zipFontLabel.text = MakerOldest.patternsTwenty.textRecorder;
    self.zipFontLabel.textColor = [UIColor whiteColor];
    self.zipFontLabel.font = [UIFont systemFontOfSize:14];
    self.zipFontLabel.numberOfLines = 0;
    self.zipFontLabel.textAlignment = NSTextAlignmentCenter;
    [self.earArrayNoteBackgroundView addSubview:self.zipFontLabel];
    
    
    [self.earArrayNoteBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(MakerOldest.redoneFinder.advancedWelsh, MakerOldest.redoneFinder.advancedWelsh));
        make.center.equalTo(self);
    }];
    
    [self.visionPresetLandscapeEmptyChromatic mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(MakerOldest.redoneFinder.indoorRedNap);
        make.centerX.equalTo(self.earArrayNoteBackgroundView.mas_centerX);
    }];
    
    [self.zipFontLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.visionPresetLandscapeEmptyChromatic.mas_bottom).offset(MakerOldest.redoneFinder.indoorRedNap);
        make.centerX.equalTo(self.earArrayNoteBackgroundView.mas_centerX);
        make.left.equalTo(self.earArrayNoteBackgroundView.mas_left).offset(MakerOldest.redoneFinder.featRawPipe);
        make.right.equalTo(self.earArrayNoteBackgroundView.mas_right).offset(-MakerOldest.redoneFinder.featRawPipe);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)offCharMayText:(NSString *)text {
    self.zipFontLabel.text = text;
    
    
    CGFloat freeWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.zipFontLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[FunnelArmManager shared] bedShiftMoveWindow];
    CGFloat loudDogWidth = MIN(MAX(120, freeWidth + 2 * 8), window.bounds.size.width);
    [self.earArrayNoteBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(loudDogWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)furlongsApplyWindow {
    [self itsAdjustFinderWalkMagentaRectifiedText:MakerOldest.patternsTwenty.textRecorder];
}

+ (void)itsAdjustFinderWalkMagentaRectifiedText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[FunnelArmManager shared] bedShiftMoveWindow];
        
        if (!generalSpringView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            generalSpringView = [[FetchSenseView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            generalSpringView.center = window.center;
        }
        if (!generalSpringView.superview) {
            [window addSubview:generalSpringView];
        }
        [generalSpringView offCharMayText:text];
        [generalSpringView startAnimating];
    });
}

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


+ (FetchSenseView *)zipWetLowYardView:(UIView *)view {
    return [self zipWetLowYardView:view withText:MakerOldest.patternsTwenty.textRecorder];
}

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

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

@end
