






#import "PubEqualTheLabel.h"
#import "DenyQuarter.h"
#import "UIImage+EyeImage.h"

@implementation PubEqualTheLabel

+ (PubEqualTheLabel *)soloSpotlightLabel {
    return [self soloSpotlightLabel:YES];
}

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

    NSAttributedString *floaterPanSurgeProgressAnd = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage renewCarbonKinUseBlueName:DenyQuarter.nowPinReport.sigmaGramLossySobDeltaPrior] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        floaterPanSurgeProgressAnd = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = DenyQuarter.netAcuteLowRow.lowSegmented;
    NSMutableAttributedString *userEarlyWhite = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange alertPermanent = [text rangeOfString:DenyQuarter.netAcuteLowRow.filmGrayInvert];
    if (alertPermanent.location != NSNotFound) {
        [userEarlyWhite addAttribute:NSForegroundColorAttributeName value:[DenyQuarter sameAppleColor] range:alertPermanent];
        [userEarlyWhite addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:alertPermanent];
    }

    
    NSMutableAttributedString *carbonSmoothAppendingSinkPassword = [[NSMutableAttributedString alloc] init];
    if (floaterPanSurgeProgressAnd) {
        [carbonSmoothAppendingSinkPassword appendAttributedString:floaterPanSurgeProgressAnd];
    }
    [carbonSmoothAppendingSinkPassword appendAttributedString:userEarlyWhite];
    
    label.attributedText = carbonSmoothAppendingSinkPassword;
    
    
    UITapGestureRecognizer *blobSinArm = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(fixingHandleMomentaryNodeEye:)];
    [label addGestureRecognizer:blobSinArm];
    
    return label;
}

- (void)setBasicHoldFocal:(BOOL)basicHoldFocal {
    _basicHoldFocal = !basicHoldFocal;
    [self seeHandlingItsCarSucceededDueLabel:self];
}

- (void)fixingHandleMomentaryNodeEye:(UITapGestureRecognizer *)blobSinArm {
    PubEqualTheLabel *label = (PubEqualTheLabel *)blobSinArm.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 eggLinkFill = [blobSinArm locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint bandStrengthPassivelySlidingMode = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint factoryCosmicKerningChromiumHardSave = CGPointMake(
        eggLinkFill.x - bandStrengthPassivelySlidingMode.x,
        eggLinkFill.y - bandStrengthPassivelySlidingMode.y
    );
    
    
    __block BOOL unfocusedAxes = 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 wideCarBad;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&wideCarBad];
            
            
            CGRect decayRect = [layoutManager boundingRectForGlyphRange:wideCarBad
                                                      inTextContainer:textContainer];
            
            
            CGRect gramMidTiedRect = CGRectOffset(decayRect, bandStrengthPassivelySlidingMode.x, bandStrengthPassivelySlidingMode.y);
            
            
            if (CGRectContainsPoint(gramMidTiedRect, eggLinkFill)) {
                unfocusedAxes = YES;
                *stop = YES;
            }
        }
    }];
    
    if (unfocusedAxes) {
        
        
        [self seeHandlingItsCarSucceededDueLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:factoryCosmicKerningChromiumHardSave
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *gaspText = label.attributedText.string;
    NSRange alertPermanent = [gaspText rangeOfString:DenyQuarter.netAcuteLowRow.filmGrayInvert];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, alertPermanent)) {
        
        
        if (self.drizzleFooterEnableIdentitySpeakWebpage) {
            self.drizzleFooterEnableIdentitySpeakWebpage();
        }
    }
}


- (void)seeHandlingItsCarSucceededDueLabel:(PubEqualTheLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL subEarlier = 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 chargeOur = !_basicHoldFocal;
        
        
        NSTextAttachment *levelVitalTwo = [[NSTextAttachment alloc] init];
        
        
        UIColor *spouseColor = chargeOur ? [DenyQuarter sameAppleColor]: UIColor.lightGrayColor;
        UIImage *fixNoiseImage = [UIImage renewCarbonKinUseBlueName:chargeOur ? DenyQuarter.nowPinReport.liveWinAllPlateJoiningCharge :DenyQuarter.nowPinReport.sigmaGramLossySobDeltaPrior];
        
        
        levelVitalTwo.image = [[fixNoiseImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:spouseColor];
        levelVitalTwo.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:levelVitalTwo range:range];
        
        _basicHoldFocal = chargeOur;
        subEarlier = YES;
        *stop = YES;
    }];
    
    if (subEarlier) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
