






#import "LoseLeadFatLabel.h"
#import "SkinEchoMen.h"
#import "UIImage+FixImage.h"

@implementation LoseLeadFatLabel

+ (LoseLeadFatLabel *)overDueOurPutLabel {
    return [self overDueOurPutLabel:YES];
}

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

    NSAttributedString *molarBalticDismissedGroupingAlgorithm = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage intentIcelandicGaspSwipeBarName:SkinEchoMen.pauseKirghiz.relativeCorrectedDaughtersMutationValueSplit] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        molarBalticDismissedGroupingAlgorithm = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = SkinEchoMen.cubePrimeToken.whoExtrasFor;
    NSMutableAttributedString *warpPinMenRoot = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange illLogSigmaAnd = [text rangeOfString:SkinEchoMen.cubePrimeToken.signGoalExtras];
    if (illLogSigmaAnd.location != NSNotFound) {
        [warpPinMenRoot addAttribute:NSForegroundColorAttributeName value:[SkinEchoMen panoramasColor] range:illLogSigmaAnd];
        [warpPinMenRoot addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:illLogSigmaAnd];
    }

    
    NSMutableAttributedString *pullHelperExternalInjectionAlive = [[NSMutableAttributedString alloc] init];
    if (molarBalticDismissedGroupingAlgorithm) {
        [pullHelperExternalInjectionAlive appendAttributedString:molarBalticDismissedGroupingAlgorithm];
    }
    [pullHelperExternalInjectionAlive appendAttributedString:warpPinMenRoot];
    
    label.attributedText = pullHelperExternalInjectionAlive;
    
    
    UITapGestureRecognizer *bagAddLeft = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(outlineAvailLikeLeftIll:)];
    [label addGestureRecognizer:bagAddLeft];
    
    return label;
}

- (void)setOwnTrackLawCup:(BOOL)ownTrackLawCup {
    _ownTrackLawCup = !ownTrackLawCup;
    [self formProtocolsTapSimpleUnlockedBreakLabel:self];
}

- (void)outlineAvailLikeLeftIll:(UITapGestureRecognizer *)bagAddLeft {
    LoseLeadFatLabel *label = (LoseLeadFatLabel *)bagAddLeft.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 toneLiveWay = [bagAddLeft locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint splatTooRepeatsCoastCat = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint magicInitiatedGreaterCellColleagueSame = CGPointMake(
        toneLiveWay.x - splatTooRepeatsCoastCat.x,
        toneLiveWay.y - splatTooRepeatsCoastCat.y
    );
    
    
    __block BOOL seeDecayWaist = 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 offHueBody;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&offHueBody];
            
            
            CGRect setupRect = [layoutManager boundingRectForGlyphRange:offHueBody
                                                      inTextContainer:textContainer];
            
            
            CGRect hasPackZoneRect = CGRectOffset(setupRect, splatTooRepeatsCoastCat.x, splatTooRepeatsCoastCat.y);
            
            
            if (CGRectContainsPoint(hasPackZoneRect, toneLiveWay)) {
                seeDecayWaist = YES;
                *stop = YES;
            }
        }
    }];
    
    if (seeDecayWaist) {
        
        
        [self formProtocolsTapSimpleUnlockedBreakLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:magicInitiatedGreaterCellColleagueSame
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *wideText = label.attributedText.string;
    NSRange illLogSigmaAnd = [wideText rangeOfString:SkinEchoMen.cubePrimeToken.signGoalExtras];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, illLogSigmaAnd)) {
        
        
        if (self.refinedRopeExactExportingDanishSpine) {
            self.refinedRopeExactExportingDanishSpine();
        }
    }
}


- (void)formProtocolsTapSimpleUnlockedBreakLabel:(LoseLeadFatLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL penFairBad = 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 bridgeKit = !_ownTrackLawCup;
        
        
        NSTextAttachment *elementsTeeth = [[NSTextAttachment alloc] init];
        
        
        UIColor *spaNapColor = bridgeKit ? [SkinEchoMen panoramasColor]: UIColor.lightGrayColor;
        UIImage *sixSugarImage = [UIImage intentIcelandicGaspSwipeBarName:bridgeKit ? SkinEchoMen.pauseKirghiz.responsesPressGrandsonNumeratorCycleDay :SkinEchoMen.pauseKirghiz.relativeCorrectedDaughtersMutationValueSplit];
        
        
        elementsTeeth.image = [[sixSugarImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:spaNapColor];
        elementsTeeth.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:elementsTeeth range:range];
        
        _ownTrackLawCup = bridgeKit;
        penFairBad = YES;
        *stop = YES;
    }];
    
    if (penFairBad) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
