






#import "DecideWithView.h"
#import "StillSockManager.h"
#import "PutBelowEye.h"
#import "Masonry.h"

@interface DecideWithView ()

@property (nonatomic, strong) UIView *insideBusLogBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *talkZoomActiveImmediateAttempter;
@property (nonatomic, strong) UILabel *batteryLabel;
@end

@implementation DecideWithView


static DecideWithView *dailyProviderView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self angleView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self angleView];
    }
    return self;
}
- (void)angleView {
    
    
    self.insideBusLogBackgroundView = [UIView new];
    self.insideBusLogBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.insideBusLogBackgroundView.layer.cornerRadius = PutBelowEye.yetRevealHow.retryRowView;
    self.insideBusLogBackgroundView.clipsToBounds = YES;
    [self addSubview:self.insideBusLogBackgroundView];
    
    
    self.talkZoomActiveImmediateAttempter = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.talkZoomActiveImmediateAttempter.color = PutBelowEye.charAlienColor;
    [self.insideBusLogBackgroundView addSubview:self.talkZoomActiveImmediateAttempter];
    
    
    self.batteryLabel = [[UILabel alloc] init];
    self.batteryLabel.text = PutBelowEye.listColumnRoot.autoRecorded;
    self.batteryLabel.textColor = [UIColor whiteColor];
    self.batteryLabel.font = [UIFont systemFontOfSize:14];
    self.batteryLabel.numberOfLines = 0;
    self.batteryLabel.textAlignment = NSTextAlignmentCenter;
    [self.insideBusLogBackgroundView addSubview:self.batteryLabel];
    
    
    [self.insideBusLogBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(PutBelowEye.yetRevealHow.hardAtomForce, PutBelowEye.yetRevealHow.hardAtomForce));
        make.center.equalTo(self);
    }];
    
    [self.talkZoomActiveImmediateAttempter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(PutBelowEye.yetRevealHow.retryRowView);
        make.centerX.equalTo(self.insideBusLogBackgroundView.mas_centerX);
    }];
    
    [self.batteryLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.talkZoomActiveImmediateAttempter.mas_bottom).offset(PutBelowEye.yetRevealHow.retryRowView);
        make.centerX.equalTo(self.insideBusLogBackgroundView.mas_centerX);
        make.left.equalTo(self.insideBusLogBackgroundView.mas_left).offset(PutBelowEye.yetRevealHow.modelOwnBus);
        make.right.equalTo(self.insideBusLogBackgroundView.mas_right).offset(-PutBelowEye.yetRevealHow.modelOwnBus);
    }];
    
    
    self.hidden = YES;
}



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

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

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


+ (void)existingSugarWindow {
    [self nepaliEncodedEditorsIgnoredBusSlantText:PutBelowEye.listColumnRoot.autoRecorded];
}

+ (void)nepaliEncodedEditorsIgnoredBusSlantText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[StillSockManager shared] tenRomanCaseWindow];
        
        if (!dailyProviderView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            dailyProviderView = [[DecideWithView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            dailyProviderView.center = window.center;
        }
        if (!dailyProviderView.superview) {
            [window addSubview:dailyProviderView];
        }
        [dailyProviderView wakeStreetText:text];
        [dailyProviderView startAnimating];
    });
}

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


+ (DecideWithView *)slantDitheredView:(UIView *)view {
    return [self slantDitheredView:view withText:PutBelowEye.listColumnRoot.autoRecorded];
}

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

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

@end
