






#import "MapLicenseView.h"
#import "MatrixFixManager.h"
#import "DistantEach.h"
#import "Masonry.h"

@interface MapLicenseView ()

@property (nonatomic, strong) UIView *binScopeFairBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *heapTenDatabaseWonCap;
@property (nonatomic, strong) UILabel *unknownLabel;
@end

@implementation MapLicenseView


static MapLicenseView *cornerSkippedView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self leaveView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self leaveView];
    }
    return self;
}
- (void)leaveView {
    
    
    self.binScopeFairBackgroundView = [UIView new];
    self.binScopeFairBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.binScopeFairBackgroundView.layer.cornerRadius = DistantEach.whoFrenchMin.catPointEach;
    self.binScopeFairBackgroundView.clipsToBounds = YES;
    [self addSubview:self.binScopeFairBackgroundView];
    
    
    self.heapTenDatabaseWonCap = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.heapTenDatabaseWonCap.color = DistantEach.tildePastColor;
    [self.binScopeFairBackgroundView addSubview:self.heapTenDatabaseWonCap];
    
    
    self.unknownLabel = [[UILabel alloc] init];
    self.unknownLabel.text = DistantEach.earMayTopModel.depthHuePlus;
    self.unknownLabel.textColor = [UIColor whiteColor];
    self.unknownLabel.font = [UIFont systemFontOfSize:14];
    self.unknownLabel.numberOfLines = 0;
    self.unknownLabel.textAlignment = NSTextAlignmentCenter;
    [self.binScopeFairBackgroundView addSubview:self.unknownLabel];
    
    
    [self.binScopeFairBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(DistantEach.whoFrenchMin.dogHairBusCar, DistantEach.whoFrenchMin.dogHairBusCar));
        make.center.equalTo(self);
    }];
    
    [self.heapTenDatabaseWonCap mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(DistantEach.whoFrenchMin.catPointEach);
        make.centerX.equalTo(self.binScopeFairBackgroundView.mas_centerX);
    }];
    
    [self.unknownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.heapTenDatabaseWonCap.mas_bottom).offset(DistantEach.whoFrenchMin.catPointEach);
        make.centerX.equalTo(self.binScopeFairBackgroundView.mas_centerX);
        make.left.equalTo(self.binScopeFairBackgroundView.mas_left).offset(DistantEach.whoFrenchMin.scoreTriple);
        make.right.equalTo(self.binScopeFairBackgroundView.mas_right).offset(-DistantEach.whoFrenchMin.scoreTriple);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)ringRawNowText:(NSString *)text {
    self.unknownLabel.text = text;
    
    
    CGFloat sendWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.unknownLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[MatrixFixManager shared] lawStylisticWindow];
    CGFloat funJoinWidth = MIN(MAX(120, sendWidth + 2 * 8), window.bounds.size.width);
    [self.binScopeFairBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(funJoinWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)gallonTeacherWindow {
    [self mathCivilWelshFunShiftYahooText:DistantEach.earMayTopModel.depthHuePlus];
}

+ (void)mathCivilWelshFunShiftYahooText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[MatrixFixManager shared] lawStylisticWindow];
        
        if (!cornerSkippedView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            cornerSkippedView = [[MapLicenseView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            cornerSkippedView.center = window.center;
        }
        if (!cornerSkippedView.superview) {
            [window addSubview:cornerSkippedView];
        }
        [cornerSkippedView ringRawNowText:text];
        [cornerSkippedView startAnimating];
    });
}

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


+ (MapLicenseView *)awakeEastStopView:(UIView *)view {
    return [self awakeEastStopView:view withText:DistantEach.earMayTopModel.depthHuePlus];
}

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

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

@end
