






#import "AnotherWrapLabel.h"
#import "BounceBrief.h"
#import "UIImage+BoxImage.h"

@implementation AnotherWrapLabel

+ (AnotherWrapLabel *)askUserDidCutLabel {
    return [self askUserDidCutLabel:YES];
}

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

    NSAttributedString *rareDecibelOverallAddFont = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage satisfiedBigLoudCallExtraName:BounceBrief.cropSobCanon.entryDailyLoadingAssignSurrogateMiles] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        rareDecibelOverallAddFont = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = BounceBrief.airDigitSobSee.illYetRectum;
    NSMutableAttributedString *labelSeeLawMid = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange emailBriefRain = [text rangeOfString:BounceBrief.airDigitSobSee.chatDashAreArm];
    if (emailBriefRain.location != NSNotFound) {
        [labelSeeLawMid addAttribute:NSForegroundColorAttributeName value:[BounceBrief randomIllColor] range:emailBriefRain];
        [labelSeeLawMid addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:emailBriefRain];
    }

    
    NSMutableAttributedString *trustedNordicSparseTildeSlide = [[NSMutableAttributedString alloc] init];
    if (rareDecibelOverallAddFont) {
        [trustedNordicSparseTildeSlide appendAttributedString:rareDecibelOverallAddFont];
    }
    [trustedNordicSparseTildeSlide appendAttributedString:labelSeeLawMid];
    
    label.attributedText = trustedNordicSparseTildeSlide;
    
    
    UITapGestureRecognizer *wasModeCat = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(panoramasHailHourlyFaeroeseMen:)];
    [label addGestureRecognizer:wasModeCat];
    
    return label;
}

- (void)setTrustMayOurNet:(BOOL)trustMayOurNet {
    _trustMayOurNet = !trustMayOurNet;
    [self constantsEvictionCheckedSafetyProvideAnotherLabel:self];
}

- (void)panoramasHailHourlyFaeroeseMen:(UITapGestureRecognizer *)wasModeCat {
    AnotherWrapLabel *label = (AnotherWrapLabel *)wasModeCat.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 itsTapBayer = [wasModeCat locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint observePrintComposedEveryExtras = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint denseRenderDrivePinEffectBefore = CGPointMake(
        itsTapBayer.x - observePrintComposedEveryExtras.x,
        itsTapBayer.y - observePrintComposedEveryExtras.y
    );
    
    
    __block BOOL slowCocoaSafe = 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 pubWalkAir;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&pubWalkAir];
            
            
            CGRect spellRect = [layoutManager boundingRectForGlyphRange:pubWalkAir
                                                      inTextContainer:textContainer];
            
            
            CGRect pubWhiteArmRect = CGRectOffset(spellRect, observePrintComposedEveryExtras.x, observePrintComposedEveryExtras.y);
            
            
            if (CGRectContainsPoint(pubWhiteArmRect, itsTapBayer)) {
                slowCocoaSafe = YES;
                *stop = YES;
            }
        }
    }];
    
    if (slowCocoaSafe) {
        
        
        [self constantsEvictionCheckedSafetyProvideAnotherLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:denseRenderDrivePinEffectBefore
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *loudText = label.attributedText.string;
    NSRange emailBriefRain = [loudText rangeOfString:BounceBrief.airDigitSobSee.chatDashAreArm];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, emailBriefRain)) {
        
        
        if (self.polishDescribeReaderNearLinearImmediate) {
            self.polishDescribeReaderNearLinearImmediate();
        }
    }
}


- (void)constantsEvictionCheckedSafetyProvideAnotherLabel:(AnotherWrapLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL capUndoSpa = 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 manganese = !_trustMayOurNet;
        
        
        NSTextAttachment *hashCoastBase = [[NSTextAttachment alloc] init];
        
        
        UIColor *divideColor = manganese ? [BounceBrief randomIllColor]: UIColor.lightGrayColor;
        UIImage *typeDownImage = [UIImage satisfiedBigLoudCallExtraName:manganese ? BounceBrief.cropSobCanon.nominalCellSlabModalNotifiedReturn :BounceBrief.cropSobCanon.entryDailyLoadingAssignSurrogateMiles];
        
        
        hashCoastBase.image = [[typeDownImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:divideColor];
        hashCoastBase.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:hashCoastBase range:range];
        
        _trustMayOurNet = manganese;
        capUndoSpa = YES;
        *stop = YES;
    }];
    
    if (capUndoSpa) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
