






#import "TouchHowEggLabel.h"
#import "WinSubAbove.h"
#import "UIImage+TooImage.h"

@implementation TouchHowEggLabel

+ (TouchHowEggLabel *)telephotoFoodLabel {
    return [self telephotoFoodLabel:YES];
}

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

    NSAttributedString *liveTenSexContainsResign = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage cricketKinSaveElevationDiskName:WinSubAbove.swipeFlagDay.overdueOverflowDaysGramKilovoltsCoulombs] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        liveTenSexContainsResign = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = WinSubAbove.resourcesCanon.whiteInstall;
    NSMutableAttributedString *spokenDaughter = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange extrasEngraved = [text rangeOfString:WinSubAbove.resourcesCanon.stereoIdleScan];
    if (extrasEngraved.location != NSNotFound) {
        [spokenDaughter addAttribute:NSForegroundColorAttributeName value:[WinSubAbove nearbyAreColor] range:extrasEngraved];
        [spokenDaughter addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:extrasEngraved];
    }

    
    NSMutableAttributedString *neutralNotationCursorsHybridDescended = [[NSMutableAttributedString alloc] init];
    if (liveTenSexContainsResign) {
        [neutralNotationCursorsHybridDescended appendAttributedString:liveTenSexContainsResign];
    }
    [neutralNotationCursorsHybridDescended appendAttributedString:spokenDaughter];
    
    label.attributedText = neutralNotationCursorsHybridDescended;
    
    
    UITapGestureRecognizer *sourceSite = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(angleSetupClampedCancelingArray:)];
    [label addGestureRecognizer:sourceSite];
    
    return label;
}

- (void)setIllHasShapeThe:(BOOL)illHasShapeThe {
    _illHasShapeThe = !illHasShapeThe;
    [self brotherBankPrintableBundlesMoviePlaybackLabel:self];
}

- (void)angleSetupClampedCancelingArray:(UITapGestureRecognizer *)sourceSite {
    TouchHowEggLabel *label = (TouchHowEggLabel *)sourceSite.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 howFlagBits = [sourceSite locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint danishBroadcastRunningOnceIndexes = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint samplesUnlockTrainingReceivesSocialArray = CGPointMake(
        howFlagBits.x - danishBroadcastRunningOnceIndexes.x,
        howFlagBits.y - danishBroadcastRunningOnceIndexes.y
    );
    
    
    __block BOOL liftUsedBleed = 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 dogEarDisk;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&dogEarDisk];
            
            
            CGRect stampRect = [layoutManager boundingRectForGlyphRange:dogEarDisk
                                                      inTextContainer:textContainer];
            
            
            CGRect handFourRunRect = CGRectOffset(stampRect, danishBroadcastRunningOnceIndexes.x, danishBroadcastRunningOnceIndexes.y);
            
            
            if (CGRectContainsPoint(handFourRunRect, howFlagBits)) {
                liftUsedBleed = YES;
                *stop = YES;
            }
        }
    }];
    
    if (liftUsedBleed) {
        
        
        [self brotherBankPrintableBundlesMoviePlaybackLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:samplesUnlockTrainingReceivesSocialArray
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *gainText = label.attributedText.string;
    NSRange extrasEngraved = [gainText rangeOfString:WinSubAbove.resourcesCanon.stereoIdleScan];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, extrasEngraved)) {
        
        
        if (self.butterflyRomanDevicesPiecePeakCreated) {
            self.butterflyRomanDevicesPiecePeakCreated();
        }
    }
}


- (void)brotherBankPrintableBundlesMoviePlaybackLabel:(TouchHowEggLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL periodBold = 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 arrowJust = !_illHasShapeThe;
        
        
        NSTextAttachment *pointGramPush = [[NSTextAttachment alloc] init];
        
        
        UIColor *finderColor = arrowJust ? [WinSubAbove nearbyAreColor]: UIColor.lightGrayColor;
        UIImage *faxThumbImage = [UIImage cricketKinSaveElevationDiskName:arrowJust ? WinSubAbove.swipeFlagDay.produceGatheringKazakhRingLastSpa :WinSubAbove.swipeFlagDay.overdueOverflowDaysGramKilovoltsCoulombs];
        
        
        pointGramPush.image = [[faxThumbImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:finderColor];
        pointGramPush.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:pointGramPush range:range];
        
        _illHasShapeThe = arrowJust;
        periodBold = YES;
        *stop = YES;
    }];
    
    if (periodBold) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
