






#import "HallOldestView.h"
#import "WasFillerManager.h"
#import "ButPhonetic.h"
#import "Masonry.h"

@interface HallOldestView ()

@property (nonatomic, strong) UIView *offFoldForceBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *tripleRecentlyCiphersSchoolSupport;
@property (nonatomic, strong) UILabel *homeOptLabel;
@end

@implementation HallOldestView


static HallOldestView *pubWetBuilderView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self raiseView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self raiseView];
    }
    return self;
}
- (void)raiseView {
    
    
    self.offFoldForceBackgroundView = [UIView new];
    self.offFoldForceBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.offFoldForceBackgroundView.layer.cornerRadius = 2.0;
    self.offFoldForceBackgroundView.clipsToBounds = YES;
    [self addSubview:self.offFoldForceBackgroundView];
    
    
    self.tripleRecentlyCiphersSchoolSupport = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.tripleRecentlyCiphersSchoolSupport.color = ButPhonetic.sonLegacyColor;
    [self.offFoldForceBackgroundView addSubview:self.tripleRecentlyCiphersSchoolSupport];
    
    
    self.homeOptLabel = [[UILabel alloc] init];
    self.homeOptLabel.text = ButPhonetic.snowTabWhoDrum.legacyStereo;
    self.homeOptLabel.textColor = [UIColor whiteColor];
    self.homeOptLabel.font = [UIFont systemFontOfSize:14];
    self.homeOptLabel.numberOfLines = 0;
    self.homeOptLabel.textAlignment = NSTextAlignmentCenter;
    [self.offFoldForceBackgroundView addSubview:self.homeOptLabel];
    
    
    [self.offFoldForceBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(ButPhonetic.ditheredFast.beganSobStart, ButPhonetic.ditheredFast.beganSobStart));
        make.center.equalTo(self);
    }];
    
    [self.tripleRecentlyCiphersSchoolSupport mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ButPhonetic.ditheredFast.charHexIndex);
        make.centerX.equalTo(self.offFoldForceBackgroundView.mas_centerX);
    }];
    
    [self.homeOptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.tripleRecentlyCiphersSchoolSupport.mas_bottom).offset(ButPhonetic.ditheredFast.charHexIndex);
        make.centerX.equalTo(self.offFoldForceBackgroundView.mas_centerX);
        make.left.equalTo(self.offFoldForceBackgroundView.mas_left).offset(ButPhonetic.ditheredFast.alarmCancel);
        make.right.equalTo(self.offFoldForceBackgroundView.mas_right).offset(-ButPhonetic.ditheredFast.alarmCancel);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)kindTabHowText:(NSString *)text {
    self.homeOptLabel.text = text;
    
    
    CGFloat portWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.homeOptLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[WasFillerManager shared] delaySubPickWindow];
    CGFloat topLoudWidth = MIN(MAX(120, portWidth + 2 * 8), window.bounds.size.width);
    [self.offFoldForceBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(topLoudWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)proximityMealWindow {
    [self lockingShareFontHundredInsertRelatedText:ButPhonetic.snowTabWhoDrum.legacyStereo];
}

+ (void)lockingShareFontHundredInsertRelatedText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[WasFillerManager shared] delaySubPickWindow];
        
        if (!pubWetBuilderView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            pubWetBuilderView = [[HallOldestView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            pubWetBuilderView.center = window.center;
        }
        if (!pubWetBuilderView.superview) {
            [window addSubview:pubWetBuilderView];
        }
        [pubWetBuilderView kindTabHowText:text];
        [pubWetBuilderView startAnimating];
    });
}

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


+ (HallOldestView *)kitGreenDraftView:(UIView *)view {
    return [self kitGreenDraftView:view withText:ButPhonetic.snowTabWhoDrum.legacyStereo];
}

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

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

@end
