






#import "HourEndEraView.h"
#import "WeekEulerManager.h"
#import "TextualTemp.h"
#import "Masonry.h"

@interface HourEndEraView ()

@property (nonatomic, strong) UIView *effectiveBagBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *measuredAloneCompanyLossyCount;
@property (nonatomic, strong) UILabel *funEndsLabel;
@end

@implementation HourEndEraView


static HourEndEraView *frameOddErrorView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self errorView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self errorView];
    }
    return self;
}
- (void)errorView {
    
    
    self.effectiveBagBackgroundView = [UIView new];
    self.effectiveBagBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.effectiveBagBackgroundView.layer.cornerRadius = TextualTemp.cancelsParse.burstNumeric;
    self.effectiveBagBackgroundView.clipsToBounds = YES;
    [self addSubview:self.effectiveBagBackgroundView];
    
    
    self.measuredAloneCompanyLossyCount = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.measuredAloneCompanyLossyCount.color = TextualTemp.longBoostColor;
    [self.effectiveBagBackgroundView addSubview:self.measuredAloneCompanyLossyCount];
    
    
    self.funEndsLabel = [[UILabel alloc] init];
    self.funEndsLabel.text = TextualTemp.mindSnowHeader.relatedSleet;
    self.funEndsLabel.textColor = [UIColor whiteColor];
    self.funEndsLabel.font = [UIFont systemFontOfSize:14];
    self.funEndsLabel.numberOfLines = 0;
    self.funEndsLabel.textAlignment = NSTextAlignmentCenter;
    [self.effectiveBagBackgroundView addSubview:self.funEndsLabel];
    
    
    [self.effectiveBagBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(TextualTemp.cancelsParse.kilogramsSafe, TextualTemp.cancelsParse.kilogramsSafe));
        make.center.equalTo(self);
    }];
    
    [self.measuredAloneCompanyLossyCount mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(TextualTemp.cancelsParse.burstNumeric);
        make.centerX.equalTo(self.effectiveBagBackgroundView.mas_centerX);
    }];
    
    [self.funEndsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.measuredAloneCompanyLossyCount.mas_bottom).offset(TextualTemp.cancelsParse.burstNumeric);
        make.centerX.equalTo(self.effectiveBagBackgroundView.mas_centerX);
        make.left.equalTo(self.effectiveBagBackgroundView.mas_left).offset(TextualTemp.cancelsParse.rowsSeedUse);
        make.right.equalTo(self.effectiveBagBackgroundView.mas_right).offset(-TextualTemp.cancelsParse.rowsSeedUse);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)talkMiddleText:(NSString *)text {
    self.funEndsLabel.text = text;
    
    
    CGFloat loudWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.funEndsLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[WeekEulerManager shared] sonAssignOwnWindow];
    CGFloat addPushWidth = MIN(MAX(120, loudWidth + 2 * 8), window.bounds.size.width);
    [self.effectiveBagBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(addPushWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)tipCutAngularWindow {
    [self keyChromaNearProtocolsDominantMountText:TextualTemp.mindSnowHeader.relatedSleet];
}

+ (void)keyChromaNearProtocolsDominantMountText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[WeekEulerManager shared] sonAssignOwnWindow];
        
        if (!frameOddErrorView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            frameOddErrorView = [[HourEndEraView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            frameOddErrorView.center = window.center;
        }
        if (!frameOddErrorView.superview) {
            [window addSubview:frameOddErrorView];
        }
        [frameOddErrorView talkMiddleText:text];
        [frameOddErrorView startAnimating];
    });
}

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


+ (HourEndEraView *)offProjectSpaView:(UIView *)view {
    return [self offProjectSpaView:view withText:TextualTemp.mindSnowHeader.relatedSleet];
}

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

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

@end
