






#import "TenRouteMaxLabel.h"
#import "HerLaunched.h"
#import "UIImage+TenImage.h"

@implementation TenRouteMaxLabel

+ (TenRouteMaxLabel *)whoElementOneLabel {
    return [self whoElementOneLabel:YES];
}

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

    NSAttributedString *passwordsPromptQuitSpaceWatery = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage todayClippingReloadBeatMacintoshName:HerLaunched.brownFairKin.menHasDisplaySpeechItalicsRectified] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        passwordsPromptQuitSpaceWatery = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = HerLaunched.pinCarOuterMan.widgetChroma;
    NSMutableAttributedString *liftPrettyMole = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange largerRateShow = [text rangeOfString:HerLaunched.pinCarOuterMan.eitherWorkouts];
    if (largerRateShow.location != NSNotFound) {
        [liftPrettyMole addAttribute:NSForegroundColorAttributeName value:[HerLaunched ironGuideColor] range:largerRateShow];
        [liftPrettyMole addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:largerRateShow];
    }

    
    NSMutableAttributedString *faxNapMorePoolWin = [[NSMutableAttributedString alloc] init];
    if (passwordsPromptQuitSpaceWatery) {
        [faxNapMorePoolWin appendAttributedString:passwordsPromptQuitSpaceWatery];
    }
    [faxNapMorePoolWin appendAttributedString:liftPrettyMole];
    
    label.attributedText = faxNapMorePoolWin;
    
    
    UITapGestureRecognizer *pinNotLink = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(lengthFinishingFilenamesAuthorDeparture:)];
    [label addGestureRecognizer:pinNotLink];
    
    return label;
}

- (void)setPreciseManager:(BOOL)preciseManager {
    _preciseManager = !preciseManager;
    [self salientMemberMegabytesStrictArtworkReturnLabel:self];
}

- (void)lengthFinishingFilenamesAuthorDeparture:(UITapGestureRecognizer *)pinNotLink {
    TenRouteMaxLabel *label = (TenRouteMaxLabel *)pinNotLink.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 startUptime = [pinNotLink locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint managedShutterSingularPressesCricket = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint originalFlushTorqueEpsilonOnceIdentity = CGPointMake(
        startUptime.x - managedShutterSingularPressesCricket.x,
        startUptime.y - managedShutterSingularPressesCricket.y
    );
    
    
    __block BOOL tipShuffleDry = 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 wetSongAsk;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&wetSongAsk];
            
            
            CGRect northRect = [layoutManager boundingRectForGlyphRange:wetSongAsk
                                                      inTextContainer:textContainer];
            
            
            CGRect speakOutTooRect = CGRectOffset(northRect, managedShutterSingularPressesCricket.x, managedShutterSingularPressesCricket.y);
            
            
            if (CGRectContainsPoint(speakOutTooRect, startUptime)) {
                tipShuffleDry = YES;
                *stop = YES;
            }
        }
    }];
    
    if (tipShuffleDry) {
        
        
        [self salientMemberMegabytesStrictArtworkReturnLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:originalFlushTorqueEpsilonOnceIdentity
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *spanText = label.attributedText.string;
    NSRange largerRateShow = [spanText rangeOfString:HerLaunched.pinCarOuterMan.eitherWorkouts];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, largerRateShow)) {
        
        
        if (self.sceneCutDestroyPopoverDirectionGender) {
            self.sceneCutDestroyPopoverDirectionGender();
        }
    }
}


- (void)salientMemberMegabytesStrictArtworkReturnLabel:(TenRouteMaxLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL nowFixEast = 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 focalThin = !_preciseManager;
        
        
        NSTextAttachment *forGreenPivot = [[NSTextAttachment alloc] init];
        
        
        UIColor *oddIcyColor = focalThin ? [HerLaunched ironGuideColor]: UIColor.lightGrayColor;
        UIImage *atomGrayImage = [UIImage todayClippingReloadBeatMacintoshName:focalThin ? HerLaunched.brownFairKin.loopDirtyLoopYetSafeFollow :HerLaunched.brownFairKin.menHasDisplaySpeechItalicsRectified];
        
        
        forGreenPivot.image = [[atomGrayImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:oddIcyColor];
        forGreenPivot.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:forGreenPivot range:range];
        
        _preciseManager = focalThin;
        nowFixEast = YES;
        *stop = YES;
    }];
    
    if (nowFixEast) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
