






#import "WayBracketView.h"
#import "HockeySeeManager.h"
#import "LearnWeekly.h"
#import "Masonry.h"

@interface WayBracketView ()

@property (nonatomic, strong) UIView *subBluePressBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *policyUploadedAudioResumedInferiors;
@property (nonatomic, strong) UILabel *creatorLabel;
@end

@implementation WayBracketView


static WayBracketView *signOverwriteView = 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.subBluePressBackgroundView = [UIView new];
    self.subBluePressBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.subBluePressBackgroundView.layer.cornerRadius = LearnWeekly.reuseRenewal.fatExpectDue;
    self.subBluePressBackgroundView.clipsToBounds = YES;
    [self addSubview:self.subBluePressBackgroundView];
    
    
    self.policyUploadedAudioResumedInferiors = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.policyUploadedAudioResumedInferiors.color = LearnWeekly.youBorderColor;
    [self.subBluePressBackgroundView addSubview:self.policyUploadedAudioResumedInferiors];
    
    
    self.creatorLabel = [[UILabel alloc] init];
    self.creatorLabel.text = LearnWeekly.estonianBanner.bagScheduler;
    self.creatorLabel.textColor = [UIColor whiteColor];
    self.creatorLabel.font = [UIFont systemFontOfSize:14];
    self.creatorLabel.numberOfLines = 0;
    self.creatorLabel.textAlignment = NSTextAlignmentCenter;
    [self.subBluePressBackgroundView addSubview:self.creatorLabel];
    
    
    [self.subBluePressBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(LearnWeekly.reuseRenewal.fitWasPubBack, LearnWeekly.reuseRenewal.fitWasPubBack));
        make.center.equalTo(self);
    }];
    
    [self.policyUploadedAudioResumedInferiors mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(LearnWeekly.reuseRenewal.fatExpectDue);
        make.centerX.equalTo(self.subBluePressBackgroundView.mas_centerX);
    }];
    
    [self.creatorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.policyUploadedAudioResumedInferiors.mas_bottom).offset(LearnWeekly.reuseRenewal.fatExpectDue);
        make.centerX.equalTo(self.subBluePressBackgroundView.mas_centerX);
        make.left.equalTo(self.subBluePressBackgroundView.mas_left).offset(LearnWeekly.reuseRenewal.burstVolume);
        make.right.equalTo(self.subBluePressBackgroundView.mas_right).offset(-LearnWeekly.reuseRenewal.burstVolume);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)upperMatchText:(NSString *)text {
    self.creatorLabel.text = text;
    
    
    CGFloat execWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.creatorLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[HockeySeeManager shared] teamReturnedWindow];
    CGFloat derivedWidth = MIN(MAX(120, execWidth + 2 * 8), window.bounds.size.width);
    [self.subBluePressBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(derivedWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)winCountryYouWindow {
    [self knowFourthKindBadgeOperationChromeText:LearnWeekly.estonianBanner.bagScheduler];
}

+ (void)knowFourthKindBadgeOperationChromeText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[HockeySeeManager shared] teamReturnedWindow];
        
        if (!signOverwriteView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            signOverwriteView = [[WayBracketView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            signOverwriteView.center = window.center;
        }
        if (!signOverwriteView.superview) {
            [window addSubview:signOverwriteView];
        }
        [signOverwriteView upperMatchText:text];
        [signOverwriteView startAnimating];
    });
}

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


+ (WayBracketView *)ourPutUseJustView:(UIView *)view {
    return [self ourPutUseJustView:view withText:LearnWeekly.estonianBanner.bagScheduler];
}

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

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

@end
