






#import "ClickInnerView.h"
#import "UnpluggedManager.h"
#import "PinMovement.h"
#import "Masonry.h"

@interface ClickInnerView ()

@property (nonatomic, strong) UIView *menPartiallyBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *genreNordicLoveAnswerTarget;
@property (nonatomic, strong) UILabel *sonChatLabel;
@end

@implementation ClickInnerView


static ClickInnerView *adoptAddPrintView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self crossView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self crossView];
    }
    return self;
}
- (void)crossView {
    
    
    self.menPartiallyBackgroundView = [UIView new];
    self.menPartiallyBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.menPartiallyBackgroundView.layer.cornerRadius = 2.0;
    self.menPartiallyBackgroundView.clipsToBounds = YES;
    [self addSubview:self.menPartiallyBackgroundView];
    
    
    self.genreNordicLoveAnswerTarget = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.genreNordicLoveAnswerTarget.color = PinMovement.unorderedColor;
    [self.menPartiallyBackgroundView addSubview:self.genreNordicLoveAnswerTarget];
    
    
    self.sonChatLabel = [[UILabel alloc] init];
    self.sonChatLabel.text = PinMovement.otherPhasePlug.datumCompact;
    self.sonChatLabel.textColor = [UIColor whiteColor];
    self.sonChatLabel.font = [UIFont systemFontOfSize:14];
    self.sonChatLabel.numberOfLines = 0;
    self.sonChatLabel.textAlignment = NSTextAlignmentCenter;
    [self.menPartiallyBackgroundView addSubview:self.sonChatLabel];
    
    
    [self.menPartiallyBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(PinMovement.cupFormatSun.herManOwnUser, PinMovement.cupFormatSun.herManOwnUser));
        make.center.equalTo(self);
    }];
    
    [self.genreNordicLoveAnswerTarget mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(PinMovement.cupFormatSun.menUniversal);
        make.centerX.equalTo(self.menPartiallyBackgroundView.mas_centerX);
    }];
    
    [self.sonChatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.genreNordicLoveAnswerTarget.mas_bottom).offset(PinMovement.cupFormatSun.menUniversal);
        make.centerX.equalTo(self.menPartiallyBackgroundView.mas_centerX);
        make.left.equalTo(self.menPartiallyBackgroundView.mas_left).offset(PinMovement.cupFormatSun.foundTipCar);
        make.right.equalTo(self.menPartiallyBackgroundView.mas_right).offset(-PinMovement.cupFormatSun.foundTipCar);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)notRateAirText:(NSString *)text {
    self.sonChatLabel.text = text;
    
    
    CGFloat lockWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.sonChatLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[UnpluggedManager shared] gainMusicMayWindow];
    CGFloat wetTreeWidth = MIN(MAX(120, lockWidth + 2 * 8), window.bounds.size.width);
    [self.menPartiallyBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(wetTreeWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)waxBlackTwistWindow {
    [self redoGrantedPartlyCenterShoulderShipmentText:PinMovement.otherPhasePlug.datumCompact];
}

+ (void)redoGrantedPartlyCenterShoulderShipmentText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[UnpluggedManager shared] gainMusicMayWindow];
        
        if (!adoptAddPrintView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            adoptAddPrintView = [[ClickInnerView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            adoptAddPrintView.center = window.center;
        }
        if (!adoptAddPrintView.superview) {
            [window addSubview:adoptAddPrintView];
        }
        [adoptAddPrintView notRateAirText:text];
        [adoptAddPrintView startAnimating];
    });
}

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


+ (ClickInnerView *)companyNormalView:(UIView *)view {
    return [self companyNormalView:view withText:PinMovement.otherPhasePlug.datumCompact];
}

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

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

@end
