






#import "UserAllJustLabel.h"
#import "MaskTheGray.h"
#import "UIImage+BedImage.h"

@implementation UserAllJustLabel

+ (UserAllJustLabel *)zoneAlarmThinLabel {
    return [self zoneAlarmThinLabel:YES];
}

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

    NSAttributedString *firstActiveAuditCatBut = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage momentGetMolarPerformerFaceName:MaskTheGray.andRomanPath.sheBarScheduledSlantResumedReliable] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        firstActiveAuditCatBut = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = MaskTheGray.starHealthHome.ascentSquash;
    NSMutableAttributedString *ornamentsStone = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange binDogStepMove = [text rangeOfString:MaskTheGray.starHealthHome.wetSayEraFoggy];
    if (binDogStepMove.location != NSNotFound) {
        [ornamentsStone addAttribute:NSForegroundColorAttributeName value:[MaskTheGray screenNapColor] range:binDogStepMove];
        [ornamentsStone addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:binDogStepMove];
    }

    
    NSMutableAttributedString *loveFloorSeeBurnKilovolts = [[NSMutableAttributedString alloc] init];
    if (firstActiveAuditCatBut) {
        [loveFloorSeeBurnKilovolts appendAttributedString:firstActiveAuditCatBut];
    }
    [loveFloorSeeBurnKilovolts appendAttributedString:ornamentsStone];
    
    label.attributedText = loveFloorSeeBurnKilovolts;
    
    
    UITapGestureRecognizer *dietaryFar = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(uppercaseOnlineFixingKilometerGeneral:)];
    [label addGestureRecognizer:dietaryFar];
    
    return label;
}

- (void)setPackEndArmFork:(BOOL)packEndArmFork {
    _packEndArmFork = !packEndArmFork;
    [self visionReceivesDuctilityGrantingFrontSurfaceLabel:self];
}

- (void)uppercaseOnlineFixingKilometerGeneral:(UITapGestureRecognizer *)dietaryFar {
    UserAllJustLabel *label = (UserAllJustLabel *)dietaryFar.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 quitMayBits = [dietaryFar locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint spectralFlipWalkOccurredPiece = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint inputPreservedBringCarbonReplaceDeliver = CGPointMake(
        quitMayBits.x - spectralFlipWalkOccurredPiece.x,
        quitMayBits.y - spectralFlipWalkOccurredPiece.y
    );
    
    
    __block BOOL bedAdvanceRet = 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 ironRecord;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&ironRecord];
            
            
            CGRect polarRect = [layoutManager boundingRectForGlyphRange:ironRecord
                                                      inTextContainer:textContainer];
            
            
            CGRect baseDecoderRect = CGRectOffset(polarRect, spectralFlipWalkOccurredPiece.x, spectralFlipWalkOccurredPiece.y);
            
            
            if (CGRectContainsPoint(baseDecoderRect, quitMayBits)) {
                bedAdvanceRet = YES;
                *stop = YES;
            }
        }
    }];
    
    if (bedAdvanceRet) {
        
        
        [self visionReceivesDuctilityGrantingFrontSurfaceLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:inputPreservedBringCarbonReplaceDeliver
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *freeText = label.attributedText.string;
    NSRange binDogStepMove = [freeText rangeOfString:MaskTheGray.starHealthHome.wetSayEraFoggy];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, binDogStepMove)) {
        
        
        if (self.launchedMasterEncodingsSyntaxTwistBandwidth) {
            self.launchedMasterEncodingsSyntaxTwistBandwidth();
        }
    }
}


- (void)visionReceivesDuctilityGrantingFrontSurfaceLabel:(UserAllJustLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL heavyIrish = 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 cosmicSix = !_packEndArmFork;
        
        
        NSTextAttachment *mathTwistKeys = [[NSTextAttachment alloc] init];
        
        
        UIColor *didTapColor = cosmicSix ? [MaskTheGray screenNapColor]: UIColor.lightGrayColor;
        UIImage *legalTooImage = [UIImage momentGetMolarPerformerFaceName:cosmicSix ? MaskTheGray.andRomanPath.beaconsStaticTopFeedTriggersExpand :MaskTheGray.andRomanPath.sheBarScheduledSlantResumedReliable];
        
        
        mathTwistKeys.image = [[legalTooImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:didTapColor];
        mathTwistKeys.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:mathTwistKeys range:range];
        
        _packEndArmFork = cosmicSix;
        heavyIrish = YES;
        *stop = YES;
    }];
    
    if (heavyIrish) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
