






#import "PageDesiredLabel.h"
#import "SheTintAuto.h"
#import "UIImage+ManImage.h"

@implementation PageDesiredLabel

+ (PageDesiredLabel *)skipHangClockLabel {
    return [self skipHangClockLabel:YES];
}

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

    NSAttributedString *bookRectifiedUptimeManyRetrieve = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage rainClosureAbortCollectStarName:SheTintAuto.linerIndexed.cornersConverterWinBodyDenseInitial] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        bookRectifiedUptimeManyRetrieve = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = SheTintAuto.floatFootThird.useTremorFun;
    NSMutableAttributedString *eyeFocalWonTen = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange bookUnsafeEdit = [text rangeOfString:SheTintAuto.floatFootThird.panoramaSeason];
    if (bookUnsafeEdit.location != NSNotFound) {
        [eyeFocalWonTen addAttribute:NSForegroundColorAttributeName value:[SheTintAuto partFocusColor] range:bookUnsafeEdit];
        [eyeFocalWonTen addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:bookUnsafeEdit];
    }

    
    NSMutableAttributedString *masteringStandUnionSlovenianPedometer = [[NSMutableAttributedString alloc] init];
    if (bookRectifiedUptimeManyRetrieve) {
        [masteringStandUnionSlovenianPedometer appendAttributedString:bookRectifiedUptimeManyRetrieve];
    }
    [masteringStandUnionSlovenianPedometer appendAttributedString:eyeFocalWonTen];
    
    label.attributedText = masteringStandUnionSlovenianPedometer;
    
    
    UITapGestureRecognizer *pencilNode = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(enumerateHasDarkenInvitedScaling:)];
    [label addGestureRecognizer:pencilNode];
    
    return label;
}

- (void)setSingleAccurate:(BOOL)singleAccurate {
    _singleAccurate = !singleAccurate;
    [self unionHealthReasonEstablishUtteranceSubgroupLabel:self];
}

- (void)enumerateHasDarkenInvitedScaling:(UITapGestureRecognizer *)pencilNode {
    PageDesiredLabel *label = (PageDesiredLabel *)pencilNode.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 execSubject = [pencilNode locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint optionalSubstringFullUsesWork = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint cupVolumesOptimizedMinShadowSmaller = CGPointMake(
        execSubject.x - optionalSubstringFullUsesWork.x,
        execSubject.y - optionalSubstringFullUsesWork.y
    );
    
    
    __block BOOL whoFlemishDay = 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 charRetSpa;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&charRetSpa];
            
            
            CGRect humanRect = [layoutManager boundingRectForGlyphRange:charRetSpa
                                                      inTextContainer:textContainer];
            
            
            CGRect saltCatMuteRect = CGRectOffset(humanRect, optionalSubstringFullUsesWork.x, optionalSubstringFullUsesWork.y);
            
            
            if (CGRectContainsPoint(saltCatMuteRect, execSubject)) {
                whoFlemishDay = YES;
                *stop = YES;
            }
        }
    }];
    
    if (whoFlemishDay) {
        
        
        [self unionHealthReasonEstablishUtteranceSubgroupLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:cupVolumesOptimizedMinShadowSmaller
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *dashText = label.attributedText.string;
    NSRange bookUnsafeEdit = [dashText rangeOfString:SheTintAuto.floatFootThird.panoramaSeason];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, bookUnsafeEdit)) {
        
        
        if (self.handledTipAscendedLibrariesNarrativeMaker) {
            self.handledTipAscendedLibrariesNarrativeMaker();
        }
    }
}


- (void)unionHealthReasonEstablishUtteranceSubgroupLabel:(PageDesiredLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL sentWindow = 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 observers = !_singleAccurate;
        
        
        NSTextAttachment *pivotMetalZip = [[NSTextAttachment alloc] init];
        
        
        UIColor *twentyColor = observers ? [SheTintAuto partFocusColor]: UIColor.lightGrayColor;
        UIImage *watchOurImage = [UIImage rainClosureAbortCollectStarName:observers ? SheTintAuto.linerIndexed.standTelephoneFeatRecycleTalkEra :SheTintAuto.linerIndexed.cornersConverterWinBodyDenseInitial];
        
        
        pivotMetalZip.image = [[watchOurImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:twentyColor];
        pivotMetalZip.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:pivotMetalZip range:range];
        
        _singleAccurate = observers;
        sentWindow = YES;
        *stop = YES;
    }];
    
    if (sentWindow) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
