






#import "BackButDashLabel.h"
#import "NapEscaping.h"
#import "UIImage+EyeImage.h"

@implementation BackButDashLabel

+ (BackButDashLabel *)momentaryToolLabel {
    return [self momentaryToolLabel:YES];
}

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

    NSAttributedString *napAutomaticBadmintonYetLanguage = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage logSliceFaxBeginBodyName:NapEscaping.restoringWay.pronounLockResolvedBurstProvidersNumbers] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        napAutomaticBadmintonYetLanguage = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = NapEscaping.sigmaTabBedKit.goalForwards;
    NSMutableAttributedString *oddStayFormMan = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange bounceObscured = [text rangeOfString:NapEscaping.sigmaTabBedKit.yetPathSumTeam];
    if (bounceObscured.location != NSNotFound) {
        [oddStayFormMan addAttribute:NSForegroundColorAttributeName value:[NapEscaping feedBayerColor] range:bounceObscured];
        [oddStayFormMan addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:bounceObscured];
    }

    
    NSMutableAttributedString *decoderAskBadLossySpanish = [[NSMutableAttributedString alloc] init];
    if (napAutomaticBadmintonYetLanguage) {
        [decoderAskBadLossySpanish appendAttributedString:napAutomaticBadmintonYetLanguage];
    }
    [decoderAskBadLossySpanish appendAttributedString:oddStayFormMan];
    
    label.attributedText = decoderAskBadLossySpanish;
    
    
    UITapGestureRecognizer *promiseBin = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(tapEulerCreateFastDiamond:)];
    [label addGestureRecognizer:promiseBin];
    
    return label;
}

- (void)setCarbonSaturate:(BOOL)carbonSaturate {
    _carbonSaturate = !carbonSaturate;
    [self coverCoverSingleLongestLooseMutableLabel:self];
}

- (void)tapEulerCreateFastDiamond:(UITapGestureRecognizer *)promiseBin {
    BackButDashLabel *label = (BackButDashLabel *)promiseBin.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 darkManWalk = [promiseBin locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint secureAppleArrangedTheBasic = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint mapSecretIndigoStackedWireReadable = CGPointMake(
        darkManWalk.x - secureAppleArrangedTheBasic.x,
        darkManWalk.y - secureAppleArrangedTheBasic.y
    );
    
    
    __block BOOL strategyEvery = 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 leadRectum;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&leadRectum];
            
            
            CGRect lowerRect = [layoutManager boundingRectForGlyphRange:leadRectum
                                                      inTextContainer:textContainer];
            
            
            CGRect wetPlainButRect = CGRectOffset(lowerRect, secureAppleArrangedTheBasic.x, secureAppleArrangedTheBasic.y);
            
            
            if (CGRectContainsPoint(wetPlainButRect, darkManWalk)) {
                strategyEvery = YES;
                *stop = YES;
            }
        }
    }];
    
    if (strategyEvery) {
        
        
        [self coverCoverSingleLongestLooseMutableLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:mapSecretIndigoStackedWireReadable
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *yardText = label.attributedText.string;
    NSRange bounceObscured = [yardText rangeOfString:NapEscaping.sigmaTabBedKit.yetPathSumTeam];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, bounceObscured)) {
        
        
        if (self.poolInvalidCricketProminentOcclusionMin) {
            self.poolInvalidCricketProminentOcclusionMin();
        }
    }
}


- (void)coverCoverSingleLongestLooseMutableLabel:(BackButDashLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL shearQueue = 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 surgeKnow = !_carbonSaturate;
        
        
        NSTextAttachment *zipCapNibbles = [[NSTextAttachment alloc] init];
        
        
        UIColor *boxHowColor = surgeKnow ? [NapEscaping feedBayerColor]: UIColor.lightGrayColor;
        UIImage *sceneYetImage = [UIImage logSliceFaxBeginBodyName:surgeKnow ? NapEscaping.restoringWay.cricketArtsOperandNormalParentFilters :NapEscaping.restoringWay.pronounLockResolvedBurstProvidersNumbers];
        
        
        zipCapNibbles.image = [[sceneYetImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:boxHowColor];
        zipCapNibbles.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:zipCapNibbles range:range];
        
        _carbonSaturate = surgeKnow;
        shearQueue = YES;
        *stop = YES;
    }];
    
    if (shearQueue) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
