






#import "LowReadTapsLabel.h"
#import "ExtentEuler.h"
#import "UIImage+JobImage.h"

@implementation LowReadTapsLabel

+ (LowReadTapsLabel *)setupDetectedLabel {
    return [self setupDetectedLabel:YES];
}

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

    NSAttributedString *additionsContentsMandatoryLoadSquared = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage graphicsStepperEnhanceCollapsesLaunchName:ExtentEuler.maleSubtitle.combiningRenewalJustIndianPutView] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        additionsContentsMandatoryLoadSquared = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = ExtentEuler.cutMaxEntryAny.leastMargins;
    NSMutableAttributedString *headlineForbid = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange sigmaFeedMetal = [text rangeOfString:ExtentEuler.cutMaxEntryAny.logManMatchNow];
    if (sigmaFeedMetal.location != NSNotFound) {
        [headlineForbid addAttribute:NSForegroundColorAttributeName value:[ExtentEuler ductilityColor] range:sigmaFeedMetal];
        [headlineForbid addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:sigmaFeedMetal];
    }

    
    NSMutableAttributedString *inputAllLocallyCleanupFaeroese = [[NSMutableAttributedString alloc] init];
    if (additionsContentsMandatoryLoadSquared) {
        [inputAllLocallyCleanupFaeroese appendAttributedString:additionsContentsMandatoryLoadSquared];
    }
    [inputAllLocallyCleanupFaeroese appendAttributedString:headlineForbid];
    
    label.attributedText = inputAllLocallyCleanupFaeroese;
    
    
    UITapGestureRecognizer *sayManTime = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(pageUploadIntentsRootRetained:)];
    [label addGestureRecognizer:sayManTime];
    
    return label;
}

- (void)setKeyRootMixBest:(BOOL)keyRootMixBest {
    _keyRootMixBest = !keyRootMixBest;
    [self restLeaveOrdinalIllHindiArcadeLabel:self];
}

- (void)pageUploadIntentsRootRetained:(UITapGestureRecognizer *)sayManTime {
    LowReadTapsLabel *label = (LowReadTapsLabel *)sayManTime.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 closeKinSix = [sayManTime locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint tokenEmergencyProposalWeightsFrame = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint mastersQuickDifferentHyphenCustomEgg = CGPointMake(
        closeKinSix.x - tokenEmergencyProposalWeightsFrame.x,
        closeKinSix.y - tokenEmergencyProposalWeightsFrame.y
    );
    
    
    __block BOOL cycleMarkPick = 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 ownWinRain;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&ownWinRain];
            
            
            CGRect malayRect = [layoutManager boundingRectForGlyphRange:ownWinRain
                                                      inTextContainer:textContainer];
            
            
            CGRect lostRealGetRect = CGRectOffset(malayRect, tokenEmergencyProposalWeightsFrame.x, tokenEmergencyProposalWeightsFrame.y);
            
            
            if (CGRectContainsPoint(lostRealGetRect, closeKinSix)) {
                cycleMarkPick = YES;
                *stop = YES;
            }
        }
    }];
    
    if (cycleMarkPick) {
        
        
        [self restLeaveOrdinalIllHindiArcadeLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:mastersQuickDifferentHyphenCustomEgg
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *flatText = label.attributedText.string;
    NSRange sigmaFeedMetal = [flatText rangeOfString:ExtentEuler.cutMaxEntryAny.logManMatchNow];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, sigmaFeedMetal)) {
        
        
        if (self.previousPrimariesCondensedOutputCervicalSequencer) {
            self.previousPrimariesCondensedOutputCervicalSequencer();
        }
    }
}


- (void)restLeaveOrdinalIllHindiArcadeLabel:(LowReadTapsLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL armPaceTag = 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 noticeShe = !_keyRootMixBest;
        
        
        NSTextAttachment *waxBagTapTake = [[NSTextAttachment alloc] init];
        
        
        UIColor *sayTabColor = noticeShe ? [ExtentEuler ductilityColor]: UIColor.lightGrayColor;
        UIImage *dayCountImage = [UIImage graphicsStepperEnhanceCollapsesLaunchName:noticeShe ? ExtentEuler.maleSubtitle.exchangesBatchPurposeCosmicAscendedSuggested :ExtentEuler.maleSubtitle.combiningRenewalJustIndianPutView];
        
        
        waxBagTapTake.image = [[dayCountImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:sayTabColor];
        waxBagTapTake.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:waxBagTapTake range:range];
        
        _keyRootMixBest = noticeShe;
        armPaceTag = YES;
        *stop = YES;
    }];
    
    if (armPaceTag) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
