






#import "HeavyPopWasLabel.h"
#import "BurstPetite.h"
#import "UIImage+EggImage.h"

@implementation HeavyPopWasLabel

+ (HeavyPopWasLabel *)barMenEastMixLabel {
    return [self barMenEastMixLabel:YES];
}

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

    NSAttributedString *capsFaxCallbackResolvingMood = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage lawMoodPointArteryQueryingName:BurstPetite.virtualSheet.creditsBandwidthThirdDayDeepAperture] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        capsFaxCallbackResolvingMood = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = BurstPetite.setupScheduled.displaysText;
    NSMutableAttributedString *tooSobPenPause = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange kindSlantTotal = [text rangeOfString:BurstPetite.setupScheduled.tailSubAreaMin];
    if (kindSlantTotal.location != NSNotFound) {
        [tooSobPenPause addAttribute:NSForegroundColorAttributeName value:[BurstPetite finalTurnColor] range:kindSlantTotal];
        [tooSobPenPause addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:kindSlantTotal];
    }

    
    NSMutableAttributedString *headphoneSpousesVignetteStrongestFair = [[NSMutableAttributedString alloc] init];
    if (capsFaxCallbackResolvingMood) {
        [headphoneSpousesVignetteStrongestFair appendAttributedString:capsFaxCallbackResolvingMood];
    }
    [headphoneSpousesVignetteStrongestFair appendAttributedString:tooSobPenPause];
    
    label.attributedText = headphoneSpousesVignetteStrongestFair;
    
    
    UITapGestureRecognizer *scalarSent = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(internetSixPlayDynamicExec:)];
    [label addGestureRecognizer:scalarSent];
    
    return label;
}

- (void)setCertArtistSalt:(BOOL)certArtistSalt {
    _certArtistSalt = !certArtistSalt;
    [self descentBitsCollationSlovakAddSpeedLabel:self];
}

- (void)internetSixPlayDynamicExec:(UITapGestureRecognizer *)scalarSent {
    HeavyPopWasLabel *label = (HeavyPopWasLabel *)scalarSent.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 newtonsStep = [scalarSent locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint eighteenSpellReuseMasteringSerbian = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint forwardsGatheringCapTornadoUpdateSoftball = CGPointMake(
        newtonsStep.x - eighteenSpellReuseMasteringSerbian.x,
        newtonsStep.y - eighteenSpellReuseMasteringSerbian.y
    );
    
    
    __block BOOL plugCallDatum = 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 hardLowRow;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&hardLowRow];
            
            
            CGRect malayRect = [layoutManager boundingRectForGlyphRange:hardLowRow
                                                      inTextContainer:textContainer];
            
            
            CGRect fatTryElderRect = CGRectOffset(malayRect, eighteenSpellReuseMasteringSerbian.x, eighteenSpellReuseMasteringSerbian.y);
            
            
            if (CGRectContainsPoint(fatTryElderRect, newtonsStep)) {
                plugCallDatum = YES;
                *stop = YES;
            }
        }
    }];
    
    if (plugCallDatum) {
        
        
        [self descentBitsCollationSlovakAddSpeedLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:forwardsGatheringCapTornadoUpdateSoftball
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *walkText = label.attributedText.string;
    NSRange kindSlantTotal = [walkText rangeOfString:BurstPetite.setupScheduled.tailSubAreaMin];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, kindSlantTotal)) {
        
        
        if (self.filmBeenPubTopEnhanceSmallest) {
            self.filmBeenPubTopEnhanceSmallest();
        }
    }
}


- (void)descentBitsCollationSlovakAddSpeedLabel:(HeavyPopWasLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL notMoodMix = 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 useOutlet = !_certArtistSalt;
        
        
        NSTextAttachment *justSmallAuto = [[NSTextAttachment alloc] init];
        
        
        UIColor *springColor = useOutlet ? [BurstPetite finalTurnColor]: UIColor.lightGrayColor;
        UIImage *sayFlushImage = [UIImage lawMoodPointArteryQueryingName:useOutlet ? BurstPetite.virtualSheet.freeServiceTagalogBlockerDemandDecay :BurstPetite.virtualSheet.creditsBandwidthThirdDayDeepAperture];
        
        
        justSmallAuto.image = [[sayFlushImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:springColor];
        justSmallAuto.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:justSmallAuto range:range];
        
        _certArtistSalt = useOutlet;
        notMoodMix = YES;
        *stop = YES;
    }];
    
    if (notMoodMix) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
