






#import "BarLaunchedLabel.h"
#import "BinTopLemma.h"
#import "UIImage+OptImage.h"

@implementation BarLaunchedLabel

+ (BarLaunchedLabel *)itsLiteralCutLabel {
    return [self itsLiteralCutLabel:YES];
}

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

    NSAttributedString *symptomScannerPrepareDueTwelve = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage chinaRecursiveAuditPartPintName:BinTopLemma.drainCatFair.factParseCanUnwindingMutableAffecting] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        symptomScannerPrepareDueTwelve = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = BinTopLemma.oldHitDownIron.stairPersian;
    NSMutableAttributedString *haveSunBinDust = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange saveDueArmSeek = [text rangeOfString:BinTopLemma.oldHitDownIron.lightArmSinSay];
    if (saveDueArmSeek.location != NSNotFound) {
        [haveSunBinDust addAttribute:NSForegroundColorAttributeName value:[BinTopLemma tabCookieColor] range:saveDueArmSeek];
        [haveSunBinDust addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:saveDueArmSeek];
    }

    
    NSMutableAttributedString *missingCanUnwindingTrailingBuffers = [[NSMutableAttributedString alloc] init];
    if (symptomScannerPrepareDueTwelve) {
        [missingCanUnwindingTrailingBuffers appendAttributedString:symptomScannerPrepareDueTwelve];
    }
    [missingCanUnwindingTrailingBuffers appendAttributedString:haveSunBinDust];
    
    label.attributedText = missingCanUnwindingTrailingBuffers;
    
    
    UITapGestureRecognizer *behaveEach = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(scheduledAccordingBusyMayAnchoring:)];
    [label addGestureRecognizer:behaveEach];
    
    return label;
}

- (void)setWhileRearrange:(BOOL)whileRearrange {
    _whileRearrange = !whileRearrange;
    [self didShowingHybridAvailFoggyLabelLabel:self];
}

- (void)scheduledAccordingBusyMayAnchoring:(UITapGestureRecognizer *)behaveEach {
    BarLaunchedLabel *label = (BarLaunchedLabel *)behaveEach.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 pauseUpload = [behaveEach locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint pairOutputsTargetedYetTen = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint tildeDisablingUnorderedMongolianStrengthProcessed = CGPointMake(
        pauseUpload.x - pairOutputsTargetedYetTen.x,
        pauseUpload.y - pairOutputsTargetedYetTen.y
    );
    
    
    __block BOOL armBagSpaMill = 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 badForUsed;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&badForUsed];
            
            
            CGRect emptyRect = [layoutManager boundingRectForGlyphRange:badForUsed
                                                      inTextContainer:textContainer];
            
            
            CGRect cocoaVectorRect = CGRectOffset(emptyRect, pairOutputsTargetedYetTen.x, pairOutputsTargetedYetTen.y);
            
            
            if (CGRectContainsPoint(cocoaVectorRect, pauseUpload)) {
                armBagSpaMill = YES;
                *stop = YES;
            }
        }
    }];
    
    if (armBagSpaMill) {
        
        
        [self didShowingHybridAvailFoggyLabelLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:tildeDisablingUnorderedMongolianStrengthProcessed
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *selfText = label.attributedText.string;
    NSRange saveDueArmSeek = [selfText rangeOfString:BinTopLemma.oldHitDownIron.lightArmSinSay];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, saveDueArmSeek)) {
        
        
        if (self.addressesBlindingOpaqueTheRebuildFeed) {
            self.addressesBlindingOpaqueTheRebuildFeed();
        }
    }
}


- (void)didShowingHybridAvailFoggyLabelLabel:(BarLaunchedLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL sinkDogMan = 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 badStatic = !_whileRearrange;
        
        
        NSTextAttachment *dueSpineYahoo = [[NSTextAttachment alloc] init];
        
        
        UIColor *outletColor = badStatic ? [BinTopLemma tabCookieColor]: UIColor.lightGrayColor;
        UIImage *smoothedImage = [UIImage chinaRecursiveAuditPartPintName:badStatic ? BinTopLemma.drainCatFair.thicknessZeroSymptomDownInuitCup :BinTopLemma.drainCatFair.factParseCanUnwindingMutableAffecting];
        
        
        dueSpineYahoo.image = [[smoothedImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:outletColor];
        dueSpineYahoo.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:dueSpineYahoo range:range];
        
        _whileRearrange = badStatic;
        sinkDogMan = YES;
        *stop = YES;
    }];
    
    if (sinkDogMan) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
