






#import "BlueTailWaxLabel.h"
#import "ScrollDatum.h"
#import "UIImage+SeeImage.h"

@implementation BlueTailWaxLabel

+ (BlueTailWaxLabel *)forHueHostingLabel {
    return [self forHueHostingLabel:YES];
}

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

    NSAttributedString *selectionBannerDocumentFrameMounted = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage broadcastExtractFlushedTopSentName:ScrollDatum.tildeStopHit.holdTrailingZipVibrancyHeapBehaviors] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        selectionBannerDocumentFrameMounted = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = ScrollDatum.spanMarkCutter.sheEightLove;
    NSMutableAttributedString *literAngleLead = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange hisWideMixThat = [text rangeOfString:ScrollDatum.spanMarkCutter.lowSlabDeepEnd];
    if (hisWideMixThat.location != NSNotFound) {
        [literAngleLead addAttribute:NSForegroundColorAttributeName value:[ScrollDatum cinematicColor] range:hisWideMixThat];
        [literAngleLead addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:hisWideMixThat];
    }

    
    NSMutableAttributedString *operationLateTableDefinesBayer = [[NSMutableAttributedString alloc] init];
    if (selectionBannerDocumentFrameMounted) {
        [operationLateTableDefinesBayer appendAttributedString:selectionBannerDocumentFrameMounted];
    }
    [operationLateTableDefinesBayer appendAttributedString:literAngleLead];
    
    label.attributedText = operationLateTableDefinesBayer;
    
    
    UITapGestureRecognizer *muteRunEar = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(quietExpiresTurkmenSpeakersGet:)];
    [label addGestureRecognizer:muteRunEar];
    
    return label;
}

- (void)setHashGainSilent:(BOOL)hashGainSilent {
    _hashGainSilent = !hashGainSilent;
    [self aggregateSkinIdiomTremorResizeCutoffLabel:self];
}

- (void)quietExpiresTurkmenSpeakersGet:(UITapGestureRecognizer *)muteRunEar {
    BlueTailWaxLabel *label = (BlueTailWaxLabel *)muteRunEar.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 mapThirdTag = [muteRunEar locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint regionsAcrossRemainderWinDetector = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint bitsRenamingVisitedSyntheticStateProfiles = CGPointMake(
        mapThirdTag.x - regionsAcrossRemainderWinDetector.x,
        mapThirdTag.y - regionsAcrossRemainderWinDetector.y
    );
    
    
    __block BOOL manChangedLaw = 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 operandSpa;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&operandSpa];
            
            
            CGRect awakeRect = [layoutManager boundingRectForGlyphRange:operandSpa
                                                      inTextContainer:textContainer];
            
            
            CGRect infoWrapperRect = CGRectOffset(awakeRect, regionsAcrossRemainderWinDetector.x, regionsAcrossRemainderWinDetector.y);
            
            
            if (CGRectContainsPoint(infoWrapperRect, mapThirdTag)) {
                manChangedLaw = YES;
                *stop = YES;
            }
        }
    }];
    
    if (manChangedLaw) {
        
        
        [self aggregateSkinIdiomTremorResizeCutoffLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:bitsRenamingVisitedSyntheticStateProfiles
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *prepText = label.attributedText.string;
    NSRange hisWideMixThat = [prepText rangeOfString:ScrollDatum.spanMarkCutter.lowSlabDeepEnd];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, hisWideMixThat)) {
        
        
        if (self.privacyRepeatExpandingKazakhCanDecipher) {
            self.privacyRepeatExpandingKazakhCanDecipher();
        }
    }
}


- (void)aggregateSkinIdiomTremorResizeCutoffLabel:(BlueTailWaxLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL topContain = 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 treeBlend = !_hashGainSilent;
        
        
        NSTextAttachment *sumArtsBigHer = [[NSTextAttachment alloc] init];
        
        
        UIColor *lawAllColor = treeBlend ? [ScrollDatum cinematicColor]: UIColor.lightGrayColor;
        UIImage *sinMediaImage = [UIImage broadcastExtractFlushedTopSentName:treeBlend ? ScrollDatum.tildeStopHit.revertingDatabasesHitLocaleDrawingAscended :ScrollDatum.tildeStopHit.holdTrailingZipVibrancyHeapBehaviors];
        
        
        sumArtsBigHer.image = [[sinMediaImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:lawAllColor];
        sumArtsBigHer.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:sumArtsBigHer range:range];
        
        _hashGainSilent = treeBlend;
        topContain = YES;
        *stop = YES;
    }];
    
    if (topContain) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
