






#import "AreRelativeLabel.h"
#import "SafeWaxSort.h"
#import "UIImage+BadImage.h"

@implementation AreRelativeLabel

+ (AreRelativeLabel *)busApplyCloudLabel {
    return [self busApplyCloudLabel:YES];
}

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

    NSAttributedString *internetSliderFourthGatherCup = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage rawTatarLiftNicknameParagraphName:SafeWaxSort.sinLaunchCut.definedArtistCandidateStripStormHow] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        internetSliderFourthGatherCup = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = SafeWaxSort.oldBothLogStop.accordingRed;
    NSMutableAttributedString *lazyOddTooCard = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange armPongRunTree = [text rangeOfString:SafeWaxSort.oldBothLogStop.notPostOffDark];
    if (armPongRunTree.location != NSNotFound) {
        [lazyOddTooCard addAttribute:NSForegroundColorAttributeName value:[SafeWaxSort teluguDidColor] range:armPongRunTree];
        [lazyOddTooCard addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:armPongRunTree];
    }

    
    NSMutableAttributedString *speakerRequiringUnorderedSubtitleSynthesis = [[NSMutableAttributedString alloc] init];
    if (internetSliderFourthGatherCup) {
        [speakerRequiringUnorderedSubtitleSynthesis appendAttributedString:internetSliderFourthGatherCup];
    }
    [speakerRequiringUnorderedSubtitleSynthesis appendAttributedString:lazyOddTooCard];
    
    label.attributedText = speakerRequiringUnorderedSubtitleSynthesis;
    
    
    UITapGestureRecognizer *forWinBond = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(sentencesInnerAbsentAdvancedOperate:)];
    [label addGestureRecognizer:forWinBond];
    
    return label;
}

- (void)setAllCutPinSurge:(BOOL)allCutPinSurge {
    _allCutPinSurge = !allCutPinSurge;
    [self mongolianSuperiorsDisappearPackLateRawLabel:self];
}

- (void)sentencesInnerAbsentAdvancedOperate:(UITapGestureRecognizer *)forWinBond {
    AreRelativeLabel *label = (AreRelativeLabel *)forWinBond.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 observeTone = [forWinBond locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint icyMountCompletedSeeContacts = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint legacyFriendToolAbortedTruncatedOutput = CGPointMake(
        observeTone.x - icyMountCompletedSeeContacts.x,
        observeTone.y - icyMountCompletedSeeContacts.y
    );
    
    
    __block BOOL askTaskWhoLaw = 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 writeAlien;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&writeAlien];
            
            
            CGRect visitRect = [layoutManager boundingRectForGlyphRange:writeAlien
                                                      inTextContainer:textContainer];
            
            
            CGRect elementPlanRect = CGRectOffset(visitRect, icyMountCompletedSeeContacts.x, icyMountCompletedSeeContacts.y);
            
            
            if (CGRectContainsPoint(elementPlanRect, observeTone)) {
                askTaskWhoLaw = YES;
                *stop = YES;
            }
        }
    }];
    
    if (askTaskWhoLaw) {
        
        
        [self mongolianSuperiorsDisappearPackLateRawLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:legacyFriendToolAbortedTruncatedOutput
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *gramText = label.attributedText.string;
    NSRange armPongRunTree = [gramText rangeOfString:SafeWaxSort.oldBothLogStop.notPostOffDark];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, armPongRunTree)) {
        
        
        if (self.stepsonFastFootersFarsiCricketOperating) {
            self.stepsonFastFootersFarsiCricketOperating();
        }
    }
}


- (void)mongolianSuperiorsDisappearPackLateRawLabel:(AreRelativeLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL offTabMole = 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 countSock = !_allCutPinSurge;
        
        
        NSTextAttachment *ironFactAxial = [[NSTextAttachment alloc] init];
        
        
        UIColor *motionColor = countSock ? [SafeWaxSort teluguDidColor]: UIColor.lightGrayColor;
        UIImage *oldClickImage = [UIImage rawTatarLiftNicknameParagraphName:countSock ? SafeWaxSort.sinLaunchCut.welshGrayAttempterMissingHerRoll :SafeWaxSort.sinLaunchCut.definedArtistCandidateStripStormHow];
        
        
        ironFactAxial.image = [[oldClickImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:motionColor];
        ironFactAxial.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:ironFactAxial range:range];
        
        _allCutPinSurge = countSock;
        offTabMole = YES;
        *stop = YES;
    }];
    
    if (offTabMole) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
