






#import "SampleFireView.h"
#import "RotorWaitManager.h"
#import "SheTintAuto.h"
#import "Masonry.h"

@interface SampleFireView ()

@property (nonatomic, strong) UIView *memberOptSumBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *enhancedArePredictedIndexFade;
@property (nonatomic, strong) UILabel *partOptLabel;
@end

@implementation SampleFireView


static SampleFireView *tabWinCharFixView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self thumbView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self thumbView];
    }
    return self;
}
- (void)thumbView {
    
    
    self.memberOptSumBackgroundView = [UIView new];
    self.memberOptSumBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.memberOptSumBackgroundView.layer.cornerRadius = SheTintAuto.linerIndexed.stepPlateJob;
    self.memberOptSumBackgroundView.clipsToBounds = YES;
    [self addSubview:self.memberOptSumBackgroundView];
    
    
    self.enhancedArePredictedIndexFade = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.enhancedArePredictedIndexFade.color = SheTintAuto.partFocusColor;
    [self.memberOptSumBackgroundView addSubview:self.enhancedArePredictedIndexFade];
    
    
    self.partOptLabel = [[UILabel alloc] init];
    self.partOptLabel.text = SheTintAuto.floatFootThird.newtonsShake;
    self.partOptLabel.textColor = [UIColor whiteColor];
    self.partOptLabel.font = [UIFont systemFontOfSize:14];
    self.partOptLabel.numberOfLines = 0;
    self.partOptLabel.textAlignment = NSTextAlignmentCenter;
    [self.memberOptSumBackgroundView addSubview:self.partOptLabel];
    
    
    [self.memberOptSumBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(SheTintAuto.linerIndexed.tapTouchesTry, SheTintAuto.linerIndexed.tapTouchesTry));
        make.center.equalTo(self);
    }];
    
    [self.enhancedArePredictedIndexFade mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(SheTintAuto.linerIndexed.stepPlateJob);
        make.centerX.equalTo(self.memberOptSumBackgroundView.mas_centerX);
    }];
    
    [self.partOptLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.enhancedArePredictedIndexFade.mas_bottom).offset(SheTintAuto.linerIndexed.stepPlateJob);
        make.centerX.equalTo(self.memberOptSumBackgroundView.mas_centerX);
        make.left.equalTo(self.memberOptSumBackgroundView.mas_left).offset(SheTintAuto.linerIndexed.subUpperFix);
        make.right.equalTo(self.memberOptSumBackgroundView.mas_right).offset(-SheTintAuto.linerIndexed.subUpperFix);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)mightLooseText:(NSString *)text {
    self.partOptLabel.text = text;
    
    
    CGFloat viewWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.partOptLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[RotorWaitManager shared] terminateRowWindow];
    CGFloat sortSonWidth = MIN(MAX(120, viewWidth + 2 * 8), window.bounds.size.width);
    [self.memberOptSumBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(sortSonWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)belowSoftnessWindow {
    [self abortedLabeledInnerQuantityReasonStepText:SheTintAuto.floatFootThird.newtonsShake];
}

+ (void)abortedLabeledInnerQuantityReasonStepText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[RotorWaitManager shared] terminateRowWindow];
        
        if (!tabWinCharFixView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            tabWinCharFixView = [[SampleFireView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            tabWinCharFixView.center = window.center;
        }
        if (!tabWinCharFixView.superview) {
            [window addSubview:tabWinCharFixView];
        }
        [tabWinCharFixView mightLooseText:text];
        [tabWinCharFixView startAnimating];
    });
}

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


+ (SampleFireView *)optAxesLowHexView:(UIView *)view {
    return [self optAxesLowHexView:view withText:SheTintAuto.floatFootThird.newtonsShake];
}

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

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

@end
