






#import "WalkingPeakLabel.h"
#import "PlayDragTap.h"
#import "UIImage+OurImage.h"

@implementation WalkingPeakLabel

+ (WalkingPeakLabel *)minderWorkoutLabel {
    return [self minderWorkoutLabel:YES];
}

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

    NSAttributedString *moleDocumentsLappishCollisionPresent = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage affinityLatencyAdvanceUnchangedMinName:PlayDragTap.popHandshake.chainSizeShowSphereSegmentMeasured] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        moleDocumentsLappishCollisionPresent = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = PlayDragTap.andSugarSawBar.yetFemaleFor;
    NSMutableAttributedString *sliceBusWinNot = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange spacingDigital = [text rangeOfString:PlayDragTap.andSugarSawBar.mindLogSonLift];
    if (spacingDigital.location != NSNotFound) {
        [sliceBusWinNot addAttribute:NSForegroundColorAttributeName value:[PlayDragTap realUpperColor] range:spacingDigital];
        [sliceBusWinNot addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:spacingDigital];
    }

    
    NSMutableAttributedString *clinicalRequestedMergePortalExtras = [[NSMutableAttributedString alloc] init];
    if (moleDocumentsLappishCollisionPresent) {
        [clinicalRequestedMergePortalExtras appendAttributedString:moleDocumentsLappishCollisionPresent];
    }
    [clinicalRequestedMergePortalExtras appendAttributedString:sliceBusWinNot];
    
    label.attributedText = clinicalRequestedMergePortalExtras;
    
    
    UITapGestureRecognizer *gaspPeriod = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(ownHockeyInsulinApertureAwake:)];
    [label addGestureRecognizer:gaspPeriod];
    
    return label;
}

- (void)setArrayLeaseUsed:(BOOL)arrayLeaseUsed {
    _arrayLeaseUsed = !arrayLeaseUsed;
    [self mastersObsoleteSpeakingAllModalFinishLabel:self];
}

- (void)ownHockeyInsulinApertureAwake:(UITapGestureRecognizer *)gaspPeriod {
    WalkingPeakLabel *label = (WalkingPeakLabel *)gaspPeriod.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 linePintOpt = [gaspPeriod locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint tremorCatalogKeysConflictsShrink = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint pencilBendAdvancedFocalFailCatalan = CGPointMake(
        linePintOpt.x - tremorCatalogKeysConflictsShrink.x,
        linePintOpt.y - tremorCatalogKeysConflictsShrink.y
    );
    
    
    __block BOOL caseDateAlone = 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 outputsOld;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&outputsOld];
            
            
            CGRect indexRect = [layoutManager boundingRectForGlyphRange:outputsOld
                                                      inTextContainer:textContainer];
            
            
            CGRect chinaElevenRect = CGRectOffset(indexRect, tremorCatalogKeysConflictsShrink.x, tremorCatalogKeysConflictsShrink.y);
            
            
            if (CGRectContainsPoint(chinaElevenRect, linePintOpt)) {
                caseDateAlone = YES;
                *stop = YES;
            }
        }
    }];
    
    if (caseDateAlone) {
        
        
        [self mastersObsoleteSpeakingAllModalFinishLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:pencilBendAdvancedFocalFailCatalan
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *formText = label.attributedText.string;
    NSRange spacingDigital = [formText rangeOfString:PlayDragTap.andSugarSawBar.mindLogSonLift];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, spacingDigital)) {
        
        
        if (self.sheLinerAccessingShelfUpscaleNickname) {
            self.sheLinerAccessingShelfUpscaleNickname();
        }
    }
}


- (void)mastersObsoleteSpeakingAllModalFinishLabel:(WalkingPeakLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL looperSnap = 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 teluguAll = !_arrayLeaseUsed;
        
        
        NSTextAttachment *lowBestHerNet = [[NSTextAttachment alloc] init];
        
        
        UIColor *notifyColor = teluguAll ? [PlayDragTap realUpperColor]: UIColor.lightGrayColor;
        UIImage *sheetCatImage = [UIImage affinityLatencyAdvanceUnchangedMinName:teluguAll ? PlayDragTap.popHandshake.strategyResolvedPopChainLanguageMind :PlayDragTap.popHandshake.chainSizeShowSphereSegmentMeasured];
        
        
        lowBestHerNet.image = [[sheetCatImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:notifyColor];
        lowBestHerNet.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:lowBestHerNet range:range];
        
        _arrayLeaseUsed = teluguAll;
        looperSnap = YES;
        *stop = YES;
    }];
    
    if (looperSnap) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
