






#import "MealRetYardLabel.h"
#import "OutTapPlain.h"
#import "UIImage+JobImage.h"

@implementation MealRetYardLabel

+ (MealRetYardLabel *)lawFaxJumpOwnLabel {
    return [self lawFaxJumpOwnLabel:YES];
}

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

    NSAttributedString *integerAnySpatialExpensiveLetter = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage sumEstimatedHandMenstrualPanName:OutTapPlain.parentMixMay.utteranceDecipherRemembersStepUploadingPeriodic] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        integerAnySpatialExpensiveLetter = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = OutTapPlain.loudMeterMount.quietShotAll;
    NSMutableAttributedString *translateFound = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange eyeGolfSoftTwo = [text rangeOfString:OutTapPlain.loudMeterMount.trailingDialog];
    if (eyeGolfSoftTwo.location != NSNotFound) {
        [translateFound addAttribute:NSForegroundColorAttributeName value:[OutTapPlain bagOuncesColor] range:eyeGolfSoftTwo];
        [translateFound addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:eyeGolfSoftTwo];
    }

    
    NSMutableAttributedString *youEstablishSuperiorsMirroredBond = [[NSMutableAttributedString alloc] init];
    if (integerAnySpatialExpensiveLetter) {
        [youEstablishSuperiorsMirroredBond appendAttributedString:integerAnySpatialExpensiveLetter];
    }
    [youEstablishSuperiorsMirroredBond appendAttributedString:translateFound];
    
    label.attributedText = youEstablishSuperiorsMirroredBond;
    
    
    UITapGestureRecognizer *losePeople = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(nonceMinManArrangerModal:)];
    [label addGestureRecognizer:losePeople];
    
    return label;
}

- (void)setStatePassDelay:(BOOL)statePassDelay {
    _statePassDelay = !statePassDelay;
    [self refreshedSexAdditionsUpperTimeSnapLabel:self];
}

- (void)nonceMinManArrangerModal:(UITapGestureRecognizer *)losePeople {
    MealRetYardLabel *label = (MealRetYardLabel *)losePeople.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 squaredLive = [losePeople locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint quechuaEnablingKernelBoundLonger = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint forChromaQueryHigherTopMode = CGPointMake(
        squaredLive.x - quechuaEnablingKernelBoundLonger.x,
        squaredLive.y - quechuaEnablingKernelBoundLonger.y
    );
    
    
    __block BOOL goalAdvertise = 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 illOrdered;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&illOrdered];
            
            
            CGRect pieceRect = [layoutManager boundingRectForGlyphRange:illOrdered
                                                      inTextContainer:textContainer];
            
            
            CGRect retEnvelopeRect = CGRectOffset(pieceRect, quechuaEnablingKernelBoundLonger.x, quechuaEnablingKernelBoundLonger.y);
            
            
            if (CGRectContainsPoint(retEnvelopeRect, squaredLive)) {
                goalAdvertise = YES;
                *stop = YES;
            }
        }
    }];
    
    if (goalAdvertise) {
        
        
        [self refreshedSexAdditionsUpperTimeSnapLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:forChromaQueryHigherTopMode
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *lockText = label.attributedText.string;
    NSRange eyeGolfSoftTwo = [lockText rangeOfString:OutTapPlain.loudMeterMount.trailingDialog];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, eyeGolfSoftTwo)) {
        
        
        if (self.allAnimatedHerTapPageAnimate) {
            self.allAnimatedHerTapPageAnimate();
        }
    }
}


- (void)refreshedSexAdditionsUpperTimeSnapLabel:(MealRetYardLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL lowRedNote = 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 zipBiotin = !_statePassDelay;
        
        
        NSTextAttachment *jobMinOperand = [[NSTextAttachment alloc] init];
        
        
        UIColor *chromeColor = zipBiotin ? [OutTapPlain bagOuncesColor]: UIColor.lightGrayColor;
        UIImage *spaceTapImage = [UIImage sumEstimatedHandMenstrualPanName:zipBiotin ? OutTapPlain.parentMixMay.ephemeralCubicSignDropSideQuality :OutTapPlain.parentMixMay.utteranceDecipherRemembersStepUploadingPeriodic];
        
        
        jobMinOperand.image = [[spaceTapImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:chromeColor];
        jobMinOperand.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:jobMinOperand range:range];
        
        _statePassDelay = zipBiotin;
        lowRedNote = YES;
        *stop = YES;
    }];
    
    if (lowRedNote) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
