






#import "EngineerMaxLabel.h"
#import "CloudyPrice.h"
#import "UIImage+ItsImage.h"

@implementation EngineerMaxLabel

+ (EngineerMaxLabel *)bitCapsArmBadLabel {
    return [self bitCapsArmBadLabel:YES];
}

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

    NSAttributedString *protocolClippingSigningDescendedManual = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage pressEncryptSemicolonEmptySixName:CloudyPrice.resetEndsIts.gradeIndexSubscribePicturePlaneClimbing] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        protocolClippingSigningDescendedManual = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = CloudyPrice.presentedIrish.lawLevelNode;
    NSMutableAttributedString *promisedIndent = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange fillFaxSexMean = [text rangeOfString:CloudyPrice.presentedIrish.footSayKeySame];
    if (fillFaxSexMean.location != NSNotFound) {
        [promisedIndent addAttribute:NSForegroundColorAttributeName value:[CloudyPrice oneCreditColor] range:fillFaxSexMean];
        [promisedIndent addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:fillFaxSexMean];
    }

    
    NSMutableAttributedString *upsideDrumTapMenuCousin = [[NSMutableAttributedString alloc] init];
    if (protocolClippingSigningDescendedManual) {
        [upsideDrumTapMenuCousin appendAttributedString:protocolClippingSigningDescendedManual];
    }
    [upsideDrumTapMenuCousin appendAttributedString:promisedIndent];
    
    label.attributedText = upsideDrumTapMenuCousin;
    
    
    UITapGestureRecognizer *clampedAnd = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(distantAboutUndoBeforeCup:)];
    [label addGestureRecognizer:clampedAnd];
    
    return label;
}

- (void)setSaltSplitExact:(BOOL)saltSplitExact {
    _saltSplitExact = !saltSplitExact;
    [self personalSaltArmNineteenManyLooseLabel:self];
}

- (void)distantAboutUndoBeforeCup:(UITapGestureRecognizer *)clampedAnd {
    EngineerMaxLabel *label = (EngineerMaxLabel *)clampedAnd.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 duePassDark = [clampedAnd locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint kilowattsDroppedLastSilencedPresenter = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint stylusSucceedPinkWrestlingSchoolObtain = CGPointMake(
        duePassDark.x - kilowattsDroppedLastSilencedPresenter.x,
        duePassDark.y - kilowattsDroppedLastSilencedPresenter.y
    );
    
    
    __block BOOL stoneCroatian = 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 carbonBeat;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&carbonBeat];
            
            
            CGRect helloRect = [layoutManager boundingRectForGlyphRange:carbonBeat
                                                      inTextContainer:textContainer];
            
            
            CGRect wonMayBrushRect = CGRectOffset(helloRect, kilowattsDroppedLastSilencedPresenter.x, kilowattsDroppedLastSilencedPresenter.y);
            
            
            if (CGRectContainsPoint(wonMayBrushRect, duePassDark)) {
                stoneCroatian = YES;
                *stop = YES;
            }
        }
    }];
    
    if (stoneCroatian) {
        
        
        [self personalSaltArmNineteenManyLooseLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:stylusSucceedPinkWrestlingSchoolObtain
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *bikeText = label.attributedText.string;
    NSRange fillFaxSexMean = [bikeText rangeOfString:CloudyPrice.presentedIrish.footSayKeySame];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, fillFaxSexMean)) {
        
        
        if (self.wasReferenceEraPublicFiberExceeds) {
            self.wasReferenceEraPublicFiberExceeds();
        }
    }
}


- (void)personalSaltArmNineteenManyLooseLabel:(EngineerMaxLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL viewKeyAdd = 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 knowRotor = !_saltSplitExact;
        
        
        NSTextAttachment *usageIncrease = [[NSTextAttachment alloc] init];
        
        
        UIColor *wonBitColor = knowRotor ? [CloudyPrice oneCreditColor]: UIColor.lightGrayColor;
        UIImage *quickOptImage = [UIImage pressEncryptSemicolonEmptySixName:knowRotor ? CloudyPrice.resetEndsIts.nauticalThermalWeekEvictionEvictBookmark :CloudyPrice.resetEndsIts.gradeIndexSubscribePicturePlaneClimbing];
        
        
        usageIncrease.image = [[quickOptImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:wonBitColor];
        usageIncrease.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:usageIncrease range:range];
        
        _saltSplitExact = knowRotor;
        viewKeyAdd = YES;
        *stop = YES;
    }];
    
    if (viewKeyAdd) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
