






#import "FinalFollowLabel.h"
#import "LearnWeekly.h"
#import "UIImage+EarImage.h"

@implementation FinalFollowLabel

+ (FinalFollowLabel *)gigabitsWaistLabel {
    return [self gigabitsWaistLabel:YES];
}

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

    NSAttributedString *expandingScanSubResolvedFlight = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage resourcesFunAskHandoffSaltName:LearnWeekly.reuseRenewal.instantAdditiveTraveledPrepProceedFork] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        expandingScanSubResolvedFlight = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = LearnWeekly.estonianBanner.nextGujarati;
    NSMutableAttributedString *hellmanClimbed = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange timeKelvinCase = [text rangeOfString:LearnWeekly.estonianBanner.waistOrnaments];
    if (timeKelvinCase.location != NSNotFound) {
        [hellmanClimbed addAttribute:NSForegroundColorAttributeName value:[LearnWeekly youBorderColor] range:timeKelvinCase];
        [hellmanClimbed addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:timeKelvinCase];
    }

    
    NSMutableAttributedString *routeCapacityCenteringUnifiedGrade = [[NSMutableAttributedString alloc] init];
    if (expandingScanSubResolvedFlight) {
        [routeCapacityCenteringUnifiedGrade appendAttributedString:expandingScanSubResolvedFlight];
    }
    [routeCapacityCenteringUnifiedGrade appendAttributedString:hellmanClimbed];
    
    label.attributedText = routeCapacityCenteringUnifiedGrade;
    
    
    UITapGestureRecognizer *learnedPop = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(pauseKnowSubtitleModifiedPreserved:)];
    [label addGestureRecognizer:learnedPop];
    
    return label;
}

- (void)setTiedRankOutSum:(BOOL)tiedRankOutSum {
    _tiedRankOutSum = !tiedRankOutSum;
    [self molarSpecifiedPortraitsHeadphoneOptTemporalLabel:self];
}

- (void)pauseKnowSubtitleModifiedPreserved:(UITapGestureRecognizer *)learnedPop {
    FinalFollowLabel *label = (FinalFollowLabel *)learnedPop.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 rearLogoFor = [learnedPop locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint sawTwitterWillKilogramsMerge = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint scanNetOverwriteGetSpanRevoked = CGPointMake(
        rearLogoFor.x - sawTwitterWillKilogramsMerge.x,
        rearLogoFor.y - sawTwitterWillKilogramsMerge.y
    );
    
    
    __block BOOL signalingBody = 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 carKitStar;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&carKitStar];
            
            
            CGRect setupRect = [layoutManager boundingRectForGlyphRange:carKitStar
                                                      inTextContainer:textContainer];
            
            
            CGRect fatElectricRect = CGRectOffset(setupRect, sawTwitterWillKilogramsMerge.x, sawTwitterWillKilogramsMerge.y);
            
            
            if (CGRectContainsPoint(fatElectricRect, rearLogoFor)) {
                signalingBody = YES;
                *stop = YES;
            }
        }
    }];
    
    if (signalingBody) {
        
        
        [self molarSpecifiedPortraitsHeadphoneOptTemporalLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:scanNetOverwriteGetSpanRevoked
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *lineText = label.attributedText.string;
    NSRange timeKelvinCase = [lineText rangeOfString:LearnWeekly.estonianBanner.waistOrnaments];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, timeKelvinCase)) {
        
        
        if (self.seleniumBorderDiscardsBirthGaelicSlider) {
            self.seleniumBorderDiscardsBirthGaelicSlider();
        }
    }
}


- (void)molarSpecifiedPortraitsHeadphoneOptTemporalLabel:(FinalFollowLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL sunRaceHas = 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 molarSave = !_tiedRankOutSum;
        
        
        NSTextAttachment *fileMixerBook = [[NSTextAttachment alloc] init];
        
        
        UIColor *pubMenColor = molarSave ? [LearnWeekly youBorderColor]: UIColor.lightGrayColor;
        UIImage *subgroupImage = [UIImage resourcesFunAskHandoffSaltName:molarSave ? LearnWeekly.reuseRenewal.profilePathHelperDarkLeapIssue :LearnWeekly.reuseRenewal.instantAdditiveTraveledPrepProceedFork];
        
        
        fileMixerBook.image = [[subgroupImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:pubMenColor];
        fileMixerBook.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:fileMixerBook range:range];
        
        _tiedRankOutSum = molarSave;
        sunRaceHas = YES;
        *stop = YES;
    }];
    
    if (sunRaceHas) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
