






#import "RotateTowerLabel.h"
#import "SafeTradEar.h"
#import "UIImage+OffImage.h"

@implementation RotateTowerLabel

+ (RotateTowerLabel *)threeImperialLabel {
    return [self threeImperialLabel:YES];
}

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

    NSAttributedString *sedentarySphericalWidthEncodeMetrics = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage acrossPlugMoleDetachCelticName:SafeTradEar.smallestMany.effectiveSelectingWrittenHeaderRebuildReload] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        sedentarySphericalWidthEncodeMetrics = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = SafeTradEar.bankRowTapsAsk.rollTatarKey;
    NSMutableAttributedString *mailEitherJust = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange mapRaceSortWho = [text rangeOfString:SafeTradEar.bankRowTapsAsk.blackSequencer];
    if (mapRaceSortWho.location != NSNotFound) {
        [mailEitherJust addAttribute:NSForegroundColorAttributeName value:[SafeTradEar dueScreenColor] range:mapRaceSortWho];
        [mailEitherJust addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:mapRaceSortWho];
    }

    
    NSMutableAttributedString *projectsSocketRevealCompressExact = [[NSMutableAttributedString alloc] init];
    if (sedentarySphericalWidthEncodeMetrics) {
        [projectsSocketRevealCompressExact appendAttributedString:sedentarySphericalWidthEncodeMetrics];
    }
    [projectsSocketRevealCompressExact appendAttributedString:mailEitherJust];
    
    label.attributedText = projectsSocketRevealCompressExact;
    
    
    UITapGestureRecognizer *addTabSlab = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(whoObscuredOverdueBayerFinder:)];
    [label addGestureRecognizer:addTabSlab];
    
    return label;
}

- (void)setIronTryMinFast:(BOOL)ironTryMinFast {
    _ironTryMinFast = !ironTryMinFast;
    [self themeLinerPlaneLoopsNoneRequiringLabel:self];
}

- (void)whoObscuredOverdueBayerFinder:(UITapGestureRecognizer *)addTabSlab {
    RotateTowerLabel *label = (RotateTowerLabel *)addTabSlab.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 theTwoAbort = [addTabSlab locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint countedIndentPasteSatisfiedThread = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint separateUnsavedHasDiskIntegrityExpecting = CGPointMake(
        theTwoAbort.x - countedIndentPasteSatisfiedThread.x,
        theTwoAbort.y - countedIndentPasteSatisfiedThread.y
    );
    
    
    __block BOOL linerAlbumSex = 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 capsLetter;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&capsLetter];
            
            
            CGRect audioRect = [layoutManager boundingRectForGlyphRange:capsLetter
                                                      inTextContainer:textContainer];
            
            
            CGRect dayDailyWayRect = CGRectOffset(audioRect, countedIndentPasteSatisfiedThread.x, countedIndentPasteSatisfiedThread.y);
            
            
            if (CGRectContainsPoint(dayDailyWayRect, theTwoAbort)) {
                linerAlbumSex = YES;
                *stop = YES;
            }
        }
    }];
    
    if (linerAlbumSex) {
        
        
        [self themeLinerPlaneLoopsNoneRequiringLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:separateUnsavedHasDiskIntegrityExpecting
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *safeText = label.attributedText.string;
    NSRange mapRaceSortWho = [safeText rangeOfString:SafeTradEar.bankRowTapsAsk.blackSequencer];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, mapRaceSortWho)) {
        
        
        if (self.highlightCatMileDesignBrowsePashto) {
            self.highlightCatMileDesignBrowsePashto();
        }
    }
}


- (void)themeLinerPlaneLoopsNoneRequiringLabel:(RotateTowerLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL bitsYetFit = 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 parserFun = !_ironTryMinFast;
        
        
        NSTextAttachment *outNorthNoise = [[NSTextAttachment alloc] init];
        
        
        UIColor *carbonColor = parserFun ? [SafeTradEar dueScreenColor]: UIColor.lightGrayColor;
        UIImage *blinkTopImage = [UIImage acrossPlugMoleDetachCelticName:parserFun ? SafeTradEar.smallestMany.tamilRowGainEngravedPlacementAbout :SafeTradEar.smallestMany.effectiveSelectingWrittenHeaderRebuildReload];
        
        
        outNorthNoise.image = [[blinkTopImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:carbonColor];
        outNorthNoise.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:outNorthNoise range:range];
        
        _ironTryMinFast = parserFun;
        bitsYetFit = YES;
        *stop = YES;
    }];
    
    if (bitsYetFit) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
