






#import "ContextHairLabel.h"
#import "MenTintSave.h"
#import "UIImage+WasImage.h"

@implementation ContextHairLabel

+ (ContextHairLabel *)hoverPressureLabel {
    return [self hoverPressureLabel:YES];
}

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

    NSAttributedString *intersectSplitTallSourcesWas = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage cautionPreservesLevelEnglishFlowName:MenTintSave.ironRouteMix.millResizingSubmittedHeightTheHealth] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        intersectSplitTallSourcesWas = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = MenTintSave.mixerRetDogPub.swedishMolar;
    NSMutableAttributedString *ruleIrishDepth = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange helpLeadBinFar = [text rangeOfString:MenTintSave.mixerRetDogPub.lexicalRematch];
    if (helpLeadBinFar.location != NSNotFound) {
        [ruleIrishDepth addAttribute:NSForegroundColorAttributeName value:[MenTintSave sedentaryColor] range:helpLeadBinFar];
        [ruleIrishDepth addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:helpLeadBinFar];
    }

    
    NSMutableAttributedString *carbonAdapterModelSoccerLearn = [[NSMutableAttributedString alloc] init];
    if (intersectSplitTallSourcesWas) {
        [carbonAdapterModelSoccerLearn appendAttributedString:intersectSplitTallSourcesWas];
    }
    [carbonAdapterModelSoccerLearn appendAttributedString:ruleIrishDepth];
    
    label.attributedText = carbonAdapterModelSoccerLearn;
    
    
    UITapGestureRecognizer *startVital = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(settingsCupEncodingsStreamedCovariant:)];
    [label addGestureRecognizer:startVital];
    
    return label;
}

- (void)setWithCanOffMale:(BOOL)withCanOffMale {
    _withCanOffMale = !withCanOffMale;
    [self tradAliveReadyTrustFoundBendLabel:self];
}

- (void)settingsCupEncodingsStreamedCovariant:(UITapGestureRecognizer *)startVital {
    ContextHairLabel *label = (ContextHairLabel *)startVital.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 styleSexual = [startVital locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint powerSiteSonTerminalQuick = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint launchingEmergencyBinSearchSchedulerFactored = CGPointMake(
        styleSexual.x - powerSiteSonTerminalQuick.x,
        styleSexual.y - powerSiteSonTerminalQuick.y
    );
    
    
    __block BOOL adoptTooUsage = 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 sawFontHow;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&sawFontHow];
            
            
            CGRect reuseRect = [layoutManager boundingRectForGlyphRange:sawFontHow
                                                      inTextContainer:textContainer];
            
            
            CGRect agePressureRect = CGRectOffset(reuseRect, powerSiteSonTerminalQuick.x, powerSiteSonTerminalQuick.y);
            
            
            if (CGRectContainsPoint(agePressureRect, styleSexual)) {
                adoptTooUsage = YES;
                *stop = YES;
            }
        }
    }];
    
    if (adoptTooUsage) {
        
        
        [self tradAliveReadyTrustFoundBendLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:launchingEmergencyBinSearchSchedulerFactored
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *burnText = label.attributedText.string;
    NSRange helpLeadBinFar = [burnText rangeOfString:MenTintSave.mixerRetDogPub.lexicalRematch];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, helpLeadBinFar)) {
        
        
        if (self.waitingPutDemandSubscriptExpectedDeviation) {
            self.waitingPutDemandSubscriptExpectedDeviation();
        }
    }
}


- (void)tradAliveReadyTrustFoundBendLabel:(ContextHairLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL sizeCapOdd = 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 monitored = !_withCanOffMale;
        
        
        NSTextAttachment *ratePrototype = [[NSTextAttachment alloc] init];
        
        
        UIColor *eyeWhoColor = monitored ? [MenTintSave sedentaryColor]: UIColor.lightGrayColor;
        UIImage *waxInuitImage = [UIImage cautionPreservesLevelEnglishFlowName:monitored ? MenTintSave.ironRouteMix.busyUploadMobileSignScreenStep :MenTintSave.ironRouteMix.millResizingSubmittedHeightTheHealth];
        
        
        ratePrototype.image = [[waxInuitImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:eyeWhoColor];
        ratePrototype.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:ratePrototype range:range];
        
        _withCanOffMale = monitored;
        sizeCapOdd = YES;
        *stop = YES;
    }];
    
    if (sizeCapOdd) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
