






#import "CallGeneralLabel.h"
#import "ReceivedFor.h"
#import "UIImage+CatImage.h"

@implementation CallGeneralLabel

+ (CallGeneralLabel *)centeredEjectLabel {
    return [self centeredEjectLabel:YES];
}

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

    NSAttributedString *permanentBundleThemeHandleLight = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage huePromisePreservedIdleOddName:ReceivedFor.dogMagicChar.sonEarMagentaExplicitBuiltLongitude] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        permanentBundleThemeHandleLight = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = ReceivedFor.strokeMoveStep.optionHexWas;
    NSMutableAttributedString *peakCallSeeSum = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange routeFatNetRow = [text rangeOfString:ReceivedFor.strokeMoveStep.offBigAdobeZip];
    if (routeFatNetRow.location != NSNotFound) {
        [peakCallSeeSum addAttribute:NSForegroundColorAttributeName value:[ReceivedFor cubicSentColor] range:routeFatNetRow];
        [peakCallSeeSum addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:routeFatNetRow];
    }

    
    NSMutableAttributedString *touchCautionCompositeIntroCaution = [[NSMutableAttributedString alloc] init];
    if (permanentBundleThemeHandleLight) {
        [touchCautionCompositeIntroCaution appendAttributedString:permanentBundleThemeHandleLight];
    }
    [touchCautionCompositeIntroCaution appendAttributedString:peakCallSeeSum];
    
    label.attributedText = touchCautionCompositeIntroCaution;
    
    
    UITapGestureRecognizer *idleCoptic = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(furlongsPongPrepMaxFinder:)];
    [label addGestureRecognizer:idleCoptic];
    
    return label;
}

- (void)setLearnGaspMount:(BOOL)learnGaspMount {
    _learnGaspMount = !learnGaspMount;
    [self valueSobItsFlippedSchoolRunLabel:self];
}

- (void)furlongsPongPrepMaxFinder:(UITapGestureRecognizer *)idleCoptic {
    CallGeneralLabel *label = (CallGeneralLabel *)idleCoptic.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 loseFeature = [idleCoptic locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint fatPenSmoothingUseIterative = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint stepchildLongerAppendedPrimeGenreRadians = CGPointMake(
        loseFeature.x - fatPenSmoothingUseIterative.x,
        loseFeature.y - fatPenSmoothingUseIterative.y
    );
    
    
    __block BOOL yardMonitored = 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 eyeColored;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&eyeColored];
            
            
            CGRect hoverRect = [layoutManager boundingRectForGlyphRange:eyeColored
                                                      inTextContainer:textContainer];
            
            
            CGRect sonRotorHowRect = CGRectOffset(hoverRect, fatPenSmoothingUseIterative.x, fatPenSmoothingUseIterative.y);
            
            
            if (CGRectContainsPoint(sonRotorHowRect, loseFeature)) {
                yardMonitored = YES;
                *stop = YES;
            }
        }
    }];
    
    if (yardMonitored) {
        
        
        [self valueSobItsFlippedSchoolRunLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:stepchildLongerAppendedPrimeGenreRadians
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *drawText = label.attributedText.string;
    NSRange routeFatNetRow = [drawText rangeOfString:ReceivedFor.strokeMoveStep.offBigAdobeZip];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, routeFatNetRow)) {
        
        
        if (self.indexesRemembersOutputLastMinimizeAnimator) {
            self.indexesRemembersOutputLastMinimizeAnimator();
        }
    }
}


- (void)valueSobItsFlippedSchoolRunLabel:(CallGeneralLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL illAddress = 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 collision = !_learnGaspMount;
        
        
        NSTextAttachment *formTopMenThe = [[NSTextAttachment alloc] init];
        
        
        UIColor *filterColor = collision ? [ReceivedFor cubicSentColor]: UIColor.lightGrayColor;
        UIImage *feedTallImage = [UIImage huePromisePreservedIdleOddName:collision ? ReceivedFor.dogMagicChar.localityAsleepMidHumidityAngleSpa :ReceivedFor.dogMagicChar.sonEarMagentaExplicitBuiltLongitude];
        
        
        formTopMenThe.image = [[feedTallImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:filterColor];
        formTopMenThe.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:formTopMenThe range:range];
        
        _learnGaspMount = collision;
        illAddress = YES;
        *stop = YES;
    }];
    
    if (illAddress) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
