






#import "LoopEastButLabel.h"
#import "PrintFarFor.h"
#import "UIImage+MinImage.h"

@implementation LoopEastButLabel

+ (LoopEastButLabel *)airGeneralAddLabel {
    return [self airGeneralAddLabel:YES];
}

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

    NSAttributedString *lastMandarinFailPrintableQuotation = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage lossyCurlRadialUnderlinePromotionName:PrintFarFor.guideMaySelf.trapSentTemporalChunkyManagersOff] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        lastMandarinFailPrintableQuotation = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = PrintFarFor.tempSockJobHas.kinCreamyHex;
    NSMutableAttributedString *awayAfterLeave = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange selectInteract = [text rangeOfString:PrintFarFor.tempSockJobHas.endHertzDogBin];
    if (selectInteract.location != NSNotFound) {
        [awayAfterLeave addAttribute:NSForegroundColorAttributeName value:[PrintFarFor expansionColor] range:selectInteract];
        [awayAfterLeave addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:selectInteract];
    }

    
    NSMutableAttributedString *negotiateCellphoneFinalizeBalticTemporal = [[NSMutableAttributedString alloc] init];
    if (lastMandarinFailPrintableQuotation) {
        [negotiateCellphoneFinalizeBalticTemporal appendAttributedString:lastMandarinFailPrintableQuotation];
    }
    [negotiateCellphoneFinalizeBalticTemporal appendAttributedString:awayAfterLeave];
    
    label.attributedText = negotiateCellphoneFinalizeBalticTemporal;
    
    
    UITapGestureRecognizer *formFollow = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(queryingVisitCheckReportingTriggered:)];
    [label addGestureRecognizer:formFollow];
    
    return label;
}

- (void)setSaveTimeEndTap:(BOOL)saveTimeEndTap {
    _saveTimeEndTap = !saveTimeEndTap;
    [self makerBelowFullyOrderVortexOnlineLabel:self];
}

- (void)queryingVisitCheckReportingTriggered:(UITapGestureRecognizer *)formFollow {
    LoopEastButLabel *label = (LoopEastButLabel *)formFollow.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 bikeMindful = [formFollow locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint reportedLocalCapCloseAlignment = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint opaquePinNewtonsContentRevertingRows = CGPointMake(
        bikeMindful.x - reportedLocalCapCloseAlignment.x,
        bikeMindful.y - reportedLocalCapCloseAlignment.y
    );
    
    
    __block BOOL moveMidHitTry = 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 moodHitOdd;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&moodHitOdd];
            
            
            CGRect widthRect = [layoutManager boundingRectForGlyphRange:moodHitOdd
                                                      inTextContainer:textContainer];
            
            
            CGRect idiomTipPubRect = CGRectOffset(widthRect, reportedLocalCapCloseAlignment.x, reportedLocalCapCloseAlignment.y);
            
            
            if (CGRectContainsPoint(idiomTipPubRect, bikeMindful)) {
                moveMidHitTry = YES;
                *stop = YES;
            }
        }
    }];
    
    if (moveMidHitTry) {
        
        
        [self makerBelowFullyOrderVortexOnlineLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:opaquePinNewtonsContentRevertingRows
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *clipText = label.attributedText.string;
    NSRange selectInteract = [clipText rangeOfString:PrintFarFor.tempSockJobHas.endHertzDogBin];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, selectInteract)) {
        
        
        if (self.finishedConditionAccordingDragPrettyCrop) {
            self.finishedConditionAccordingDragPrettyCrop();
        }
    }
}


- (void)makerBelowFullyOrderVortexOnlineLabel:(LoopEastButLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL touchesMax = 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 memberAny = !_saveTimeEndTap;
        
        
        NSTextAttachment *stepRetBusMan = [[NSTextAttachment alloc] init];
        
        
        UIColor *seeCarColor = memberAny ? [PrintFarFor expansionColor]: UIColor.lightGrayColor;
        UIImage *itsOrderImage = [UIImage lossyCurlRadialUnderlinePromotionName:memberAny ? PrintFarFor.guideMaySelf.prefersModifiersSortInternetAndIndian :PrintFarFor.guideMaySelf.trapSentTemporalChunkyManagersOff];
        
        
        stepRetBusMan.image = [[itsOrderImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:seeCarColor];
        stepRetBusMan.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:stepRetBusMan range:range];
        
        _saveTimeEndTap = memberAny;
        touchesMax = YES;
        *stop = YES;
    }];
    
    if (touchesMax) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
