






#import "TightPubHasLabel.h"
#import "MapSheFocus.h"
#import "UIImage+SumImage.h"

@implementation TightPubHasLabel

+ (TightPubHasLabel *)tapLawDateArmLabel {
    return [self tapLawDateArmLabel:YES];
}

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

    NSAttributedString *eventShiftTargetedEffectiveTilde = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage rematchChannelsSentenceGigahertzDecideName:MapSheFocus.ownerQuality.coalesceMeasureAllocatorThumbnailLittleFit] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        eventShiftTargetedEffectiveTilde = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = MapSheFocus.catBlackPopMay.dueMegahertz;
    NSMutableAttributedString *runRunBlendIcy = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange nextWireUnsafe = [text rangeOfString:MapSheFocus.catBlackPopMay.fairGermanPath];
    if (nextWireUnsafe.location != NSNotFound) {
        [runRunBlendIcy addAttribute:NSForegroundColorAttributeName value:[MapSheFocus mayBundleColor] range:nextWireUnsafe];
        [runRunBlendIcy addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:nextWireUnsafe];
    }

    
    NSMutableAttributedString *boldfaceYearsPresentedAlphabetAudible = [[NSMutableAttributedString alloc] init];
    if (eventShiftTargetedEffectiveTilde) {
        [boldfaceYearsPresentedAlphabetAudible appendAttributedString:eventShiftTargetedEffectiveTilde];
    }
    [boldfaceYearsPresentedAlphabetAudible appendAttributedString:runRunBlendIcy];
    
    label.attributedText = boldfaceYearsPresentedAlphabetAudible;
    
    
    UITapGestureRecognizer *pivotPhone = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(millionFreestyleTwistPashtoCompress:)];
    [label addGestureRecognizer:pivotPhone];
    
    return label;
}

- (void)setFullyGuideNine:(BOOL)fullyGuideNine {
    _fullyGuideNine = !fullyGuideNine;
    [self exactSafariKernelsBuiltPredictedDogLabel:self];
}

- (void)millionFreestyleTwistPashtoCompress:(UITapGestureRecognizer *)pivotPhone {
    TightPubHasLabel *label = (TightPubHasLabel *)pivotPhone.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 youStarAway = [pivotPhone locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint defineAnimationAdoptFunctionsFar = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint evaluatedSongJouleEllipsisProxiesBurmese = CGPointMake(
        youStarAway.x - defineAnimationAdoptFunctionsFar.x,
        youStarAway.y - defineAnimationAdoptFunctionsFar.y
    );
    
    
    __block BOOL splatDominant = 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 butFlemish;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&butFlemish];
            
            
            CGRect romanRect = [layoutManager boundingRectForGlyphRange:butFlemish
                                                      inTextContainer:textContainer];
            
            
            CGRect directGuideRect = CGRectOffset(romanRect, defineAnimationAdoptFunctionsFar.x, defineAnimationAdoptFunctionsFar.y);
            
            
            if (CGRectContainsPoint(directGuideRect, youStarAway)) {
                splatDominant = YES;
                *stop = YES;
            }
        }
    }];
    
    if (splatDominant) {
        
        
        [self exactSafariKernelsBuiltPredictedDogLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:evaluatedSongJouleEllipsisProxiesBurmese
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *hailText = label.attributedText.string;
    NSRange nextWireUnsafe = [hailText rangeOfString:MapSheFocus.catBlackPopMay.fairGermanPath];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, nextWireUnsafe)) {
        
        
        if (self.dogCarbonDebuggerCallHoursWorld) {
            self.dogCarbonDebuggerCallHoursWorld();
        }
    }
}


- (void)exactSafariKernelsBuiltPredictedDogLabel:(TightPubHasLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL whoFactory = 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 sparsePin = !_fullyGuideNine;
        
        
        NSTextAttachment *adoptNeverShe = [[NSTextAttachment alloc] init];
        
        
        UIColor *getZipColor = sparsePin ? [MapSheFocus mayBundleColor]: UIColor.lightGrayColor;
        UIImage *foodDashImage = [UIImage rematchChannelsSentenceGigahertzDecideName:sparsePin ? MapSheFocus.ownerQuality.volumesKilovoltsDraftBulgarianPaperStep :MapSheFocus.ownerQuality.coalesceMeasureAllocatorThumbnailLittleFit];
        
        
        adoptNeverShe.image = [[foodDashImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:getZipColor];
        adoptNeverShe.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:adoptNeverShe range:range];
        
        _fullyGuideNine = sparsePin;
        whoFactory = YES;
        *stop = YES;
    }];
    
    if (whoFactory) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
