






#import "FitSixClaimLabel.h"
#import "SaveWayTaps.h"
#import "UIImage+RetImage.h"

@implementation FitSixClaimLabel

+ (FitSixClaimLabel *)liftAlbumTradLabel {
    return [self liftAlbumTradLabel:YES];
}

+ (FitSixClaimLabel *)liftAlbumTradLabel:(BOOL)isCheckBox {
    
    FitSixClaimLabel *label = [[FitSixClaimLabel alloc] init];
    label.numberOfLines = 0;
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor lightGrayColor];
    label.font = [UIFont systemFontOfSize:12];
    label.userInteractionEnabled = YES; 

    NSAttributedString *creationRedoUndefinedBusEntropy = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage builtOptimizeIncludesEstimatedHomepageName:SaveWayTaps.offerHitEasy.advertisePressedMetricLyricistAxialSignal] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        creationRedoUndefinedBusEntropy = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = SaveWayTaps.hueOldAreaMole.digestFunPop;
    NSMutableAttributedString *blockerEpisode = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange trainerRemoves = [text rangeOfString:SaveWayTaps.hueOldAreaMole.leavePinRunOur];
    if (trainerRemoves.location != NSNotFound) {
        [blockerEpisode addAttribute:NSForegroundColorAttributeName value:[SaveWayTaps divideRunColor] range:trainerRemoves];
        [blockerEpisode addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:trainerRemoves];
    }

    
    NSMutableAttributedString *fastBlendSunFunkMixer = [[NSMutableAttributedString alloc] init];
    if (creationRedoUndefinedBusEntropy) {
        [fastBlendSunFunkMixer appendAttributedString:creationRedoUndefinedBusEntropy];
    }
    [fastBlendSunFunkMixer appendAttributedString:blockerEpisode];
    
    label.attributedText = fastBlendSunFunkMixer;
    
    
    UITapGestureRecognizer *eyeFadeBit = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(littleTightArbiterTargetThe:)];
    [label addGestureRecognizer:eyeFadeBit];
    
    return label;
}

- (void)setBridgeStroking:(BOOL)bridgeStroking {
    _bridgeStroking = !bridgeStroking;
    [self successGatewaysKeepStiffnessUploadedPlugLabel:self];
}

- (void)littleTightArbiterTargetThe:(UITapGestureRecognizer *)eyeFadeBit {
    FitSixClaimLabel *label = (FitSixClaimLabel *)eyeFadeBit.view;
    if (!label.attributedText) return;
    
    
    NSTextStorage *textStorage = [[NSTextStorage alloc] initWithAttributedString:label.attributedText];
    NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
    NSTextContainer *textContainer = [[NSTextContainer alloc] initWithSize:label.bounds.size];
    
    textContainer.lineFragmentPadding = 0;
    textContainer.maximumNumberOfLines = label.numberOfLines;
    textContainer.lineBreakMode = label.lineBreakMode;
    
    [textStorage addLayoutManager:layoutManager];
    [layoutManager addTextContainer:textContainer];
    
    
    [layoutManager ensureLayoutForTextContainer:textContainer];
    
    
    CGPoint getFoodSink = [eyeFadeBit locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint inhalerItalicNineApplyingWay = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint azimuthPagerResolvedNoiseTeluguPop = CGPointMake(
        getFoodSink.x - inhalerItalicNineApplyingWay.x,
        getFoodSink.y - inhalerItalicNineApplyingWay.y
    );
    
    
    __block BOOL sawAfterExist = NO;
    [label.attributedText enumerateAttribute:NSAttachmentAttributeName
                                    inRange:NSMakeRange(0, label.attributedText.length)
                                    options:0
                                 usingBlock:^(id value, NSRange range, BOOL *stop) {
        if ([value isKindOfClass:[NSTextAttachment class]]) {
            
            NSRange membersSex;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&membersSex];
            
            
            CGRect arrayRect = [layoutManager boundingRectForGlyphRange:membersSex
                                                      inTextContainer:textContainer];
            
            
            CGRect downFilmTwoRect = CGRectOffset(arrayRect, inhalerItalicNineApplyingWay.x, inhalerItalicNineApplyingWay.y);
            
            
            if (CGRectContainsPoint(downFilmTwoRect, getFoodSink)) {
                sawAfterExist = YES;
                *stop = YES;
            }
        }
    }];
    
    if (sawAfterExist) {
        
        
        [self successGatewaysKeepStiffnessUploadedPlugLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:azimuthPagerResolvedNoiseTeluguPop
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *saveText = label.attributedText.string;
    NSRange trainerRemoves = [saveText rangeOfString:SaveWayTaps.hueOldAreaMole.leavePinRunOur];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, trainerRemoves)) {
        
        
        if (self.digitTooYouResignHomepageAre) {
            self.digitTooYouResignHomepageAre();
        }
    }
}


- (void)successGatewaysKeepStiffnessUploadedPlugLabel:(FitSixClaimLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL modeRetain = NO;
    
    [attributedText enumerateAttribute:NSAttachmentAttributeName
                             inRange:NSMakeRange(0, attributedText.length)
                             options:0
                          usingBlock:^(NSTextAttachment *oldAttachment, NSRange range, BOOL *stop) {
        if (![oldAttachment isKindOfClass:[NSTextAttachment class]]) return;
        
        
        BOOL lowDarken = !_bridgeStroking;
        
        
        NSTextAttachment *mindCollector = [[NSTextAttachment alloc] init];
        
        
        UIColor *repeatColor = lowDarken ? [SaveWayTaps divideRunColor]: UIColor.lightGrayColor;
        UIImage *brandDryImage = [UIImage builtOptimizeIncludesEstimatedHomepageName:lowDarken ? SaveWayTaps.offerHitEasy.slovenianPulseAnchorRouterAffineRelated :SaveWayTaps.offerHitEasy.advertisePressedMetricLyricistAxialSignal];
        
        
        mindCollector.image = [[brandDryImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:repeatColor];
        mindCollector.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:mindCollector range:range];
        
        _bridgeStroking = lowDarken;
        modeRetain = YES;
        *stop = YES;
    }];
    
    if (modeRetain) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
