






#import "DogButtonsView.h"
#import "DocumentsManager.h"
#import "TooCloudSun.h"
#import "Masonry.h"

@interface DogButtonsView ()

@property (nonatomic, strong) UIView *followSumSumBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *icyModelContainerHalftoneDefault;
@property (nonatomic, strong) UILabel *instantLabel;
@end

@implementation DogButtonsView


static DogButtonsView *assistantShotView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self whileView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self whileView];
    }
    return self;
}
- (void)whileView {
    
    
    self.followSumSumBackgroundView = [UIView new];
    self.followSumSumBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.followSumSumBackgroundView.layer.cornerRadius = TooCloudSun.seeFocusSlab.busBitsDaily;
    self.followSumSumBackgroundView.clipsToBounds = YES;
    [self addSubview:self.followSumSumBackgroundView];
    
    
    self.icyModelContainerHalftoneDefault = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.icyModelContainerHalftoneDefault.color = TooCloudSun.semicolonColor;
    [self.followSumSumBackgroundView addSubview:self.icyModelContainerHalftoneDefault];
    
    
    self.instantLabel = [[UILabel alloc] init];
    self.instantLabel.text = TooCloudSun.methodCaseItem.selfMonthOff;
    self.instantLabel.textColor = [UIColor whiteColor];
    self.instantLabel.font = [UIFont systemFontOfSize:14];
    self.instantLabel.numberOfLines = 0;
    self.instantLabel.textAlignment = NSTextAlignmentCenter;
    [self.followSumSumBackgroundView addSubview:self.instantLabel];
    
    
    [self.followSumSumBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(TooCloudSun.seeFocusSlab.draftBalanced, TooCloudSun.seeFocusSlab.draftBalanced));
        make.center.equalTo(self);
    }];
    
    [self.icyModelContainerHalftoneDefault mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(TooCloudSun.seeFocusSlab.busBitsDaily);
        make.centerX.equalTo(self.followSumSumBackgroundView.mas_centerX);
    }];
    
    [self.instantLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.icyModelContainerHalftoneDefault.mas_bottom).offset(TooCloudSun.seeFocusSlab.busBitsDaily);
        make.centerX.equalTo(self.followSumSumBackgroundView.mas_centerX);
        make.left.equalTo(self.followSumSumBackgroundView.mas_left).offset(TooCloudSun.seeFocusSlab.tagsRefresh);
        make.right.equalTo(self.followSumSumBackgroundView.mas_right).offset(-TooCloudSun.seeFocusSlab.tagsRefresh);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)pinSpaZeroText:(NSString *)text {
    self.instantLabel.text = text;
    
    
    CGFloat weekWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.instantLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[DocumentsManager shared] errorClearedWindow];
    CGFloat treeSheWidth = MIN(MAX(120, weekWidth + 2 * 8), window.bounds.size.width);
    [self.followSumSumBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(treeSheWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)torchFinishedWindow {
    [self transposeVisitWriteBorderedSymbolLeftoverText:TooCloudSun.methodCaseItem.selfMonthOff];
}

+ (void)transposeVisitWriteBorderedSymbolLeftoverText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[DocumentsManager shared] errorClearedWindow];
        
        if (!assistantShotView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            assistantShotView = [[DogButtonsView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            assistantShotView.center = window.center;
        }
        if (!assistantShotView.superview) {
            [window addSubview:assistantShotView];
        }
        [assistantShotView pinSpaZeroText:text];
        [assistantShotView startAnimating];
    });
}

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


+ (DogButtonsView *)hitOutPushWonView:(UIView *)view {
    return [self hitOutPushWonView:view withText:TooCloudSun.methodCaseItem.selfMonthOff];
}

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

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

@end
