






#import "DarkReactorLabel.h"
#import "AffectedBus.h"
#import "UIImage+LawImage.h"

@implementation DarkReactorLabel

+ (DarkReactorLabel *)catPagerBeginLabel {
    return [self catPagerBeginLabel:YES];
}

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

    NSAttributedString *mountExtendingEvictRevisionIts = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage softnessTableProtectedDisablesChunkyName:AffectedBus.mixProviders.maxDefaultsProvideSeventeenCanMiter] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        mountExtendingEvictRevisionIts = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = AffectedBus.delayOceanMale.restSmileSaw;
    NSMutableAttributedString *distinctPurple = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange quitRankUplink = [text rangeOfString:AffectedBus.delayOceanMale.sexIllMinClaim];
    if (quitRankUplink.location != NSNotFound) {
        [distinctPurple addAttribute:NSForegroundColorAttributeName value:[AffectedBus betterWhoColor] range:quitRankUplink];
        [distinctPurple addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:quitRankUplink];
    }

    
    NSMutableAttributedString *establishSaturatedDryAccuracyCircle = [[NSMutableAttributedString alloc] init];
    if (mountExtendingEvictRevisionIts) {
        [establishSaturatedDryAccuracyCircle appendAttributedString:mountExtendingEvictRevisionIts];
    }
    [establishSaturatedDryAccuracyCircle appendAttributedString:distinctPurple];
    
    label.attributedText = establishSaturatedDryAccuracyCircle;
    
    
    UITapGestureRecognizer *optSuggest = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(chinaSecureHybridAdaptorFiller:)];
    [label addGestureRecognizer:optSuggest];
    
    return label;
}

- (void)setBitMoleBurnKey:(BOOL)bitMoleBurnKey {
    _bitMoleBurnKey = !bitMoleBurnKey;
    [self noneCommonEndTomorrowFairMilesLabel:self];
}

- (void)chinaSecureHybridAdaptorFiller:(UITapGestureRecognizer *)optSuggest {
    DarkReactorLabel *label = (DarkReactorLabel *)optSuggest.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 outStakeSub = [optSuggest locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint effectContextKernelBookMan = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint manualMediumFeaturesDesktopApplyingFolder = CGPointMake(
        outStakeSub.x - effectContextKernelBookMan.x,
        outStakeSub.y - effectContextKernelBookMan.y
    );
    
    
    __block BOOL forceBookPlug = 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 repairFlat;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&repairFlat];
            
            
            CGRect arrayRect = [layoutManager boundingRectForGlyphRange:repairFlat
                                                      inTextContainer:textContainer];
            
            
            CGRect pingHelpersRect = CGRectOffset(arrayRect, effectContextKernelBookMan.x, effectContextKernelBookMan.y);
            
            
            if (CGRectContainsPoint(pingHelpersRect, outStakeSub)) {
                forceBookPlug = YES;
                *stop = YES;
            }
        }
    }];
    
    if (forceBookPlug) {
        
        
        [self noneCommonEndTomorrowFairMilesLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:manualMediumFeaturesDesktopApplyingFolder
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *meanText = label.attributedText.string;
    NSRange quitRankUplink = [meanText rangeOfString:AffectedBus.delayOceanMale.sexIllMinClaim];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, quitRankUplink)) {
        
        
        if (self.applyingLeapPopTrademarkRestLock) {
            self.applyingLeapPopTrademarkRestLock();
        }
    }
}


- (void)noneCommonEndTomorrowFairMilesLabel:(DarkReactorLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL thickHours = 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 discarded = !_bitMoleBurnKey;
        
        
        NSTextAttachment *readyExecutor = [[NSTextAttachment alloc] init];
        
        
        UIColor *earTheColor = discarded ? [AffectedBus betterWhoColor]: UIColor.lightGrayColor;
        UIImage *beginPenImage = [UIImage softnessTableProtectedDisablesChunkyName:discarded ? AffectedBus.mixProviders.vitalPartUnionBandwidthSexIcy :AffectedBus.mixProviders.maxDefaultsProvideSeventeenCanMiter];
        
        
        readyExecutor.image = [[beginPenImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:earTheColor];
        readyExecutor.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:readyExecutor range:range];
        
        _bitMoleBurnKey = discarded;
        thickHours = YES;
        *stop = YES;
    }];
    
    if (thickHours) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
