






#import "AirlineMeanLabel.h"
#import "UserArtRoot.h"
#import "UIImage+WasImage.h"

@implementation AirlineMeanLabel

+ (AirlineMeanLabel *)datumBagStakeLabel {
    return [self datumBagStakeLabel:YES];
}

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

    NSAttributedString *detectionRollSourcesRearEpsilon = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage containerModifiersAskSceneOuterName:UserArtRoot.wayAbortLove.yearContainerSleetProposedForkKind] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        detectionRollSourcesRearEpsilon = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = UserArtRoot.builtOwnSeeEar.decryptedRaw;
    NSMutableAttributedString *yesterdayStorm = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange menKitBinAlong = [text rangeOfString:UserArtRoot.builtOwnSeeEar.bothMathButTab];
    if (menKitBinAlong.location != NSNotFound) {
        [yesterdayStorm addAttribute:NSForegroundColorAttributeName value:[UserArtRoot partBoostColor] range:menKitBinAlong];
        [yesterdayStorm addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:menKitBinAlong];
    }

    
    NSMutableAttributedString *smallModifiedUnwrapRuleOwnership = [[NSMutableAttributedString alloc] init];
    if (detectionRollSourcesRearEpsilon) {
        [smallModifiedUnwrapRuleOwnership appendAttributedString:detectionRollSourcesRearEpsilon];
    }
    [smallModifiedUnwrapRuleOwnership appendAttributedString:yesterdayStorm];
    
    label.attributedText = smallModifiedUnwrapRuleOwnership;
    
    
    UITapGestureRecognizer *tenBothArm = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(deliveredStripPatchLeapTint:)];
    [label addGestureRecognizer:tenBothArm];
    
    return label;
}

- (void)setZeroFlipPutEgg:(BOOL)zeroFlipPutEgg {
    _zeroFlipPutEgg = !zeroFlipPutEgg;
    [self rowUnwindSpecifierAttitudeNotBandLabel:self];
}

- (void)deliveredStripPatchLeapTint:(UITapGestureRecognizer *)tenBothArm {
    AirlineMeanLabel *label = (AirlineMeanLabel *)tenBothArm.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 hitGoalCard = [tenBothArm locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint optFixManHitPager = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint thickSenderSendUtilityPushMale = CGPointMake(
        hitGoalCard.x - optFixManHitPager.x,
        hitGoalCard.y - optFixManHitPager.y
    );
    
    
    __block BOOL oddPictureDid = 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 redoPhotos;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&redoPhotos];
            
            
            CGRect tightRect = [layoutManager boundingRectForGlyphRange:redoPhotos
                                                      inTextContainer:textContainer];
            
            
            CGRect envelopeCanRect = CGRectOffset(tightRect, optFixManHitPager.x, optFixManHitPager.y);
            
            
            if (CGRectContainsPoint(envelopeCanRect, hitGoalCard)) {
                oddPictureDid = YES;
                *stop = YES;
            }
        }
    }];
    
    if (oddPictureDid) {
        
        
        [self rowUnwindSpecifierAttitudeNotBandLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:thickSenderSendUtilityPushMale
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *failText = label.attributedText.string;
    NSRange menKitBinAlong = [failText rangeOfString:UserArtRoot.builtOwnSeeEar.bothMathButTab];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, menKitBinAlong)) {
        
        
        if (self.presetThreeLargestPanoramasSaltSwipe) {
            self.presetThreeLargestPanoramasSaltSwipe();
        }
    }
}


- (void)rowUnwindSpecifierAttitudeNotBandLabel:(AirlineMeanLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL theMapOnce = 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 speechGet = !_zeroFlipPutEgg;
        
        
        NSTextAttachment *latvianDesign = [[NSTextAttachment alloc] init];
        
        
        UIColor *sawAllColor = speechGet ? [UserArtRoot partBoostColor]: UIColor.lightGrayColor;
        UIImage *retWristImage = [UIImage containerModifiersAskSceneOuterName:speechGet ? UserArtRoot.wayAbortLove.cellularTraverseLemmaSixDayKannada :UserArtRoot.wayAbortLove.yearContainerSleetProposedForkKind];
        
        
        latvianDesign.image = [[retWristImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:sawAllColor];
        latvianDesign.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:latvianDesign range:range];
        
        _zeroFlipPutEgg = speechGet;
        theMapOnce = YES;
        *stop = YES;
    }];
    
    if (theMapOnce) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
