






#import "RealLateDueLabel.h"
#import "VitalityTab.h"
#import "UIImage+UseImage.h"

@implementation RealLateDueLabel

+ (RealLateDueLabel *)waxOldWaitingLabel {
    return [self waxOldWaitingLabel:YES];
}

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

    NSAttributedString *swapTwistFireAdjustsSandbox = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage diskOrderedCampaignThemeAdjectiveName:VitalityTab.noneMidMicro.tapWaterEndRectifiedDanishIrish] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        swapTwistFireAdjustsSandbox = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = VitalityTab.foggyCycleUnit.sphericalLow;
    NSMutableAttributedString *terahertzTower = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange adjustingEvery = [text rangeOfString:VitalityTab.foggyCycleUnit.oldMindBagCost];
    if (adjustingEvery.location != NSNotFound) {
        [terahertzTower addAttribute:NSForegroundColorAttributeName value:[VitalityTab didCancelColor] range:adjustingEvery];
        [terahertzTower addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:adjustingEvery];
    }

    
    NSMutableAttributedString *makeDirectorSheMindfulPanorama = [[NSMutableAttributedString alloc] init];
    if (swapTwistFireAdjustsSandbox) {
        [makeDirectorSheMindfulPanorama appendAttributedString:swapTwistFireAdjustsSandbox];
    }
    [makeDirectorSheMindfulPanorama appendAttributedString:terahertzTower];
    
    label.attributedText = makeDirectorSheMindfulPanorama;
    
    
    UITapGestureRecognizer *licenseAll = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(pushLinearStrengthBusAdjective:)];
    [label addGestureRecognizer:licenseAll];
    
    return label;
}

- (void)setOccurDolbyTail:(BOOL)occurDolbyTail {
    _occurDolbyTail = !occurDolbyTail;
    [self hormoneEarElectricMinimalBinCatalogLabel:self];
}

- (void)pushLinearStrengthBusAdjective:(UITapGestureRecognizer *)licenseAll {
    RealLateDueLabel *label = (RealLateDueLabel *)licenseAll.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 northFixYou = [licenseAll locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint leaveFirmwareRevealBlindingAdjust = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint dependentVisitedContentsShortcutHusbandLatitude = CGPointMake(
        northFixYou.x - leaveFirmwareRevealBlindingAdjust.x,
        northFixYou.y - leaveFirmwareRevealBlindingAdjust.y
    );
    
    
    __block BOOL dogRareMaxWin = 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 hexJoining;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&hexJoining];
            
            
            CGRect pressRect = [layoutManager boundingRectForGlyphRange:hexJoining
                                                      inTextContainer:textContainer];
            
            
            CGRect reusableOddRect = CGRectOffset(pressRect, leaveFirmwareRevealBlindingAdjust.x, leaveFirmwareRevealBlindingAdjust.y);
            
            
            if (CGRectContainsPoint(reusableOddRect, northFixYou)) {
                dogRareMaxWin = YES;
                *stop = YES;
            }
        }
    }];
    
    if (dogRareMaxWin) {
        
        
        [self hormoneEarElectricMinimalBinCatalogLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:dependentVisitedContentsShortcutHusbandLatitude
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *filmText = label.attributedText.string;
    NSRange adjustingEvery = [filmText rangeOfString:VitalityTab.foggyCycleUnit.oldMindBagCost];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, adjustingEvery)) {
        
        
        if (self.vowelFontOptGrantedModalGrouping) {
            self.vowelFontOptGrantedModalGrouping();
        }
    }
}


- (void)hormoneEarElectricMinimalBinCatalogLabel:(RealLateDueLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL illSquared = 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 chinaTool = !_occurDolbyTail;
        
        
        NSTextAttachment *logSwappedHit = [[NSTextAttachment alloc] init];
        
        
        UIColor *sexUseColor = chinaTool ? [VitalityTab didCancelColor]: UIColor.lightGrayColor;
        UIImage *footnoteImage = [UIImage diskOrderedCampaignThemeAdjectiveName:chinaTool ? VitalityTab.noneMidMicro.shutterPolicyDecimalLiveNegateCompany :VitalityTab.noneMidMicro.tapWaterEndRectifiedDanishIrish];
        
        
        logSwappedHit.image = [[footnoteImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:sexUseColor];
        logSwappedHit.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:logSwappedHit range:range];
        
        _occurDolbyTail = chinaTool;
        illSquared = YES;
        *stop = YES;
    }];
    
    if (illSquared) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
