






#import "FiberDecodeLabel.h"
#import "PartialBest.h"
#import "UIImage+SeeImage.h"

@implementation FiberDecodeLabel

+ (FiberDecodeLabel *)armourRelatedLabel {
    return [self armourRelatedLabel:YES];
}

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

    NSAttributedString *brandMoireOccurredAllowHeight = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage reverseOptionCervicalSinhaleseSpecifiedName:PartialBest.mouseEarlier.belowResultingAirUrgencyKitVariance] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        brandMoireOccurredAllowHeight = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = PartialBest.itsOneFlowEasy.noteRadixAny;
    NSMutableAttributedString *herBagNeverAsk = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange cervicalCancel = [text rangeOfString:PartialBest.itsOneFlowEasy.arbitrarySpeed];
    if (cervicalCancel.location != NSNotFound) {
        [herBagNeverAsk addAttribute:NSForegroundColorAttributeName value:[PartialBest turnOtherColor] range:cervicalCancel];
        [herBagNeverAsk addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:cervicalCancel];
    }

    
    NSMutableAttributedString *senderReviewPutAssistiveRespects = [[NSMutableAttributedString alloc] init];
    if (brandMoireOccurredAllowHeight) {
        [senderReviewPutAssistiveRespects appendAttributedString:brandMoireOccurredAllowHeight];
    }
    [senderReviewPutAssistiveRespects appendAttributedString:herBagNeverAsk];
    
    label.attributedText = senderReviewPutAssistiveRespects;
    
    
    UITapGestureRecognizer *lightClick = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(spineRefusedBrowseRenderOwner:)];
    [label addGestureRecognizer:lightClick];
    
    return label;
}

- (void)setSpaFoggyMixOld:(BOOL)spaFoggyMixOld {
    _spaFoggyMixOld = !spaFoggyMixOld;
    [self normalArmpitWalkAuxiliaryAggregateDissolveLabel:self];
}

- (void)spineRefusedBrowseRenderOwner:(UITapGestureRecognizer *)lightClick {
    FiberDecodeLabel *label = (FiberDecodeLabel *)lightClick.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 bookmarkRaw = [lightClick locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint howLiveDispatchMediaFair = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint ouncesFunLayeringRefreshClockChanged = CGPointMake(
        bookmarkRaw.x - howLiveDispatchMediaFair.x,
        bookmarkRaw.y - howLiveDispatchMediaFair.y
    );
    
    
    __block BOOL sheNoteTopSun = 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 farOnlyOff;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&farOnlyOff];
            
            
            CGRect stackRect = [layoutManager boundingRectForGlyphRange:farOnlyOff
                                                      inTextContainer:textContainer];
            
            
            CGRect menServicesRect = CGRectOffset(stackRect, howLiveDispatchMediaFair.x, howLiveDispatchMediaFair.y);
            
            
            if (CGRectContainsPoint(menServicesRect, bookmarkRaw)) {
                sheNoteTopSun = YES;
                *stop = YES;
            }
        }
    }];
    
    if (sheNoteTopSun) {
        
        
        [self normalArmpitWalkAuxiliaryAggregateDissolveLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:ouncesFunLayeringRefreshClockChanged
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *rainText = label.attributedText.string;
    NSRange cervicalCancel = [rainText rangeOfString:PartialBest.itsOneFlowEasy.arbitrarySpeed];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, cervicalCancel)) {
        
        
        if (self.outputsQuantitySpanLocationScrollingGroup) {
            self.outputsQuantitySpanLocationScrollingGroup();
        }
    }
}


- (void)normalArmpitWalkAuxiliaryAggregateDissolveLabel:(FiberDecodeLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL objectLogo = 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 healthBad = !_spaFoggyMixOld;
        
        
        NSTextAttachment *packHandScore = [[NSTextAttachment alloc] init];
        
        
        UIColor *kitAskColor = healthBad ? [PartialBest turnOtherColor]: UIColor.lightGrayColor;
        UIImage *clearRawImage = [UIImage reverseOptionCervicalSinhaleseSpecifiedName:healthBad ? PartialBest.mouseEarlier.transformPathTooSinFooterSilence :PartialBest.mouseEarlier.belowResultingAirUrgencyKitVariance];
        
        
        packHandScore.image = [[clearRawImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:kitAskColor];
        packHandScore.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:packHandScore range:range];
        
        _spaFoggyMixOld = healthBad;
        objectLogo = YES;
        *stop = YES;
    }];
    
    if (objectLogo) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
