






#import "PopTipHomeView.h"
#import "PotentialManager.h"
#import "MenuCluster.h"
#import "Masonry.h"

@interface PopTipHomeView ()

@property (nonatomic, strong) UIView *majorHasWordBackgroundView;
@property (nonatomic, strong) UIActivityIndicatorView *sharingRepeatFatWaitWax;
@property (nonatomic, strong) UILabel *dogSeedLabel;
@end

@implementation PopTipHomeView


static PopTipHomeView *yetPanelRaiseView = nil;



- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self stripView];
    }
    return self;
}
- (instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];
    if (self) {
        [self stripView];
    }
    return self;
}
- (void)stripView {
    
    
    self.majorHasWordBackgroundView = [UIView new];
    self.majorHasWordBackgroundView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.5];
    self.majorHasWordBackgroundView.layer.cornerRadius = 2.0;
    self.majorHasWordBackgroundView.clipsToBounds = YES;
    [self addSubview:self.majorHasWordBackgroundView];
    
    
    self.sharingRepeatFatWaitWax = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleLarge];
    self.sharingRepeatFatWaitWax.color = MenuCluster.asleepYetColor;
    [self.majorHasWordBackgroundView addSubview:self.sharingRepeatFatWaitWax];
    
    
    self.dogSeedLabel = [[UILabel alloc] init];
    self.dogSeedLabel.text = MenuCluster.hallFloorExist.paperPending;
    self.dogSeedLabel.textColor = [UIColor whiteColor];
    self.dogSeedLabel.font = [UIFont systemFontOfSize:14];
    self.dogSeedLabel.numberOfLines = 0;
    self.dogSeedLabel.textAlignment = NSTextAlignmentCenter;
    [self.majorHasWordBackgroundView addSubview:self.dogSeedLabel];
    
    
    [self.majorHasWordBackgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(MenuCluster.thirteenHand.maxReadPenFun, MenuCluster.thirteenHand.maxReadPenFun));
        make.center.equalTo(self);
    }];
    
    [self.sharingRepeatFatWaitWax mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(MenuCluster.thirteenHand.errorUnknown);
        make.centerX.equalTo(self.majorHasWordBackgroundView.mas_centerX);
    }];
    
    [self.dogSeedLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.sharingRepeatFatWaitWax.mas_bottom).offset(MenuCluster.thirteenHand.errorUnknown);
        make.centerX.equalTo(self.majorHasWordBackgroundView.mas_centerX);
        make.left.equalTo(self.majorHasWordBackgroundView.mas_left).offset(MenuCluster.thirteenHand.chunkyMolar);
        make.right.equalTo(self.majorHasWordBackgroundView.mas_right).offset(-MenuCluster.thirteenHand.chunkyMolar);
    }];
    
    
    self.hidden = YES;
}



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

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

- (void)yahooVoiceText:(NSString *)text {
    self.dogSeedLabel.text = text;
    
    
    CGFloat areaWidth = [text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX)
                                          options:NSStringDrawingUsesLineFragmentOrigin
                                       attributes:@{NSFontAttributeName: self.dogSeedLabel.font}
                                          context:nil].size.width;
    UIWindow *window = [[PotentialManager shared] tapHalfOrderWindow];
    CGFloat islamicWidth = MIN(MAX(120, areaWidth + 2 * 8), window.bounds.size.width);
    [self.majorHasWordBackgroundView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(islamicWidth);
    }];
    
    [self layoutIfNeeded];
}


+ (void)panPrinterBarWindow {
    [self effectZoneZipSobLongBadgeText:MenuCluster.hallFloorExist.paperPending];
}

+ (void)effectZoneZipSobLongBadgeText:(NSString *)text {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIWindow *window = [[PotentialManager shared] tapHalfOrderWindow];
        
        if (!yetPanelRaiseView) {
            CGSize size = UIScreen.mainScreen.bounds.size;
            yetPanelRaiseView = [[PopTipHomeView alloc] initWithFrame:CGRectMake(0, 0, size.width, size.height)];
            yetPanelRaiseView.center = window.center;
        }
        if (!yetPanelRaiseView.superview) {
            [window addSubview:yetPanelRaiseView];
        }
        [yetPanelRaiseView yahooVoiceText:text];
        [yetPanelRaiseView startAnimating];
    });
}

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


+ (PopTipHomeView *)logoTooLowTwoView:(UIView *)view {
    return [self logoTooLowTwoView:view withText:MenuCluster.hallFloorExist.paperPending];
}

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

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

@end
