






#import "AlienExposeLabel.h"
#import "SubBondFour.h"
#import "UIImage+GetImage.h"

@implementation AlienExposeLabel

+ (AlienExposeLabel *)drainSpeakingLabel {
    return [self drainSpeakingLabel:YES];
}

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

    NSAttributedString *seventeenBoxTrailingDustMeter = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage positionOwnMeteringSourcesBookName:SubBondFour.nodeFourteen.unwindingBackwardsParserPerformsUndoUpload] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        seventeenBoxTrailingDustMeter = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = SubBondFour.injectionBlack.realLocality;
    NSMutableAttributedString *bankRejectFood = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange fadeInputNorth = [text rangeOfString:SubBondFour.injectionBlack.endpointsExits];
    if (fadeInputNorth.location != NSNotFound) {
        [bankRejectFood addAttribute:NSForegroundColorAttributeName value:[SubBondFour routeHeapColor] range:fadeInputNorth];
        [bankRejectFood addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:fadeInputNorth];
    }

    
    NSMutableAttributedString *polarNegotiatePasswordsTranslateGender = [[NSMutableAttributedString alloc] init];
    if (seventeenBoxTrailingDustMeter) {
        [polarNegotiatePasswordsTranslateGender appendAttributedString:seventeenBoxTrailingDustMeter];
    }
    [polarNegotiatePasswordsTranslateGender appendAttributedString:bankRejectFood];
    
    label.attributedText = polarNegotiatePasswordsTranslateGender;
    
    
    UITapGestureRecognizer *rowTibetan = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(itsEphemeralSinListMagic:)];
    [label addGestureRecognizer:rowTibetan];
    
    return label;
}

- (void)setWhileOddDayShe:(BOOL)whileOddDayShe {
    _whileOddDayShe = !whileOddDayShe;
    [self reverseThreadWonPopoverUseExponentsLabel:self];
}

- (void)itsEphemeralSinListMagic:(UITapGestureRecognizer *)rowTibetan {
    AlienExposeLabel *label = (AlienExposeLabel *)rowTibetan.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 maxPoloQuit = [rowTibetan locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint kilohertzKilogramStationPressedMail = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint socketDerivedSucceedCheckerPaperSticky = CGPointMake(
        maxPoloQuit.x - kilohertzKilogramStationPressedMail.x,
        maxPoloQuit.y - kilohertzKilogramStationPressedMail.y
    );
    
    
    __block BOOL chainVitalSob = 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 onePushWas;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&onePushWas];
            
            
            CGRect metalRect = [layoutManager boundingRectForGlyphRange:onePushWas
                                                      inTextContainer:textContainer];
            
            
            CGRect cloudArtPenRect = CGRectOffset(metalRect, kilohertzKilogramStationPressedMail.x, kilohertzKilogramStationPressedMail.y);
            
            
            if (CGRectContainsPoint(cloudArtPenRect, maxPoloQuit)) {
                chainVitalSob = YES;
                *stop = YES;
            }
        }
    }];
    
    if (chainVitalSob) {
        
        
        [self reverseThreadWonPopoverUseExponentsLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:socketDerivedSucceedCheckerPaperSticky
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *signText = label.attributedText.string;
    NSRange fadeInputNorth = [signText rangeOfString:SubBondFour.injectionBlack.endpointsExits];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, fadeInputNorth)) {
        
        
        if (self.coverageFoundSexSobMaxLeft) {
            self.coverageFoundSexSobMaxLeft();
        }
    }
}


- (void)reverseThreadWonPopoverUseExponentsLabel:(AlienExposeLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL voiceEject = 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 artistNet = !_whileOddDayShe;
        
        
        NSTextAttachment *fixLocalAlien = [[NSTextAttachment alloc] init];
        
        
        UIColor *toggleColor = artistNet ? [SubBondFour routeHeapColor]: UIColor.lightGrayColor;
        UIImage *yetNeverImage = [UIImage positionOwnMeteringSourcesBookName:artistNet ? SubBondFour.nodeFourteen.deleteWonLemmaForkFilmHint :SubBondFour.nodeFourteen.unwindingBackwardsParserPerformsUndoUpload];
        
        
        fixLocalAlien.image = [[yetNeverImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:toggleColor];
        fixLocalAlien.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:fixLocalAlien range:range];
        
        _whileOddDayShe = artistNet;
        voiceEject = YES;
        *stop = YES;
    }];
    
    if (voiceEject) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
