






#import "ExpireSegueLabel.h"
#import "WinNeedHang.h"
#import "UIImage+EggImage.h"

@implementation ExpireSegueLabel

+ (ExpireSegueLabel *)wayThreadsHisLabel {
    return [self wayThreadsHisLabel:YES];
}

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

    NSAttributedString *anyWireQuitTwistBrowsing = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage rearrangeKeepCutterAbsentBalancedName:WinNeedHang.chargePenSin.mailWinIterationQuickHailTwo] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        anyWireQuitTwistBrowsing = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = WinNeedHang.mapSonInputIll.beganCertAdd;
    NSMutableAttributedString *copperMantissa = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange peerIllStarKey = [text rangeOfString:WinNeedHang.mapSonInputIll.reuseTranspose];
    if (peerIllStarKey.location != NSNotFound) {
        [copperMantissa addAttribute:NSForegroundColorAttributeName value:[WinNeedHang suspendedColor] range:peerIllStarKey];
        [copperMantissa addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:peerIllStarKey];
    }

    
    NSMutableAttributedString *minPriceParentalLearnDirection = [[NSMutableAttributedString alloc] init];
    if (anyWireQuitTwistBrowsing) {
        [minPriceParentalLearnDirection appendAttributedString:anyWireQuitTwistBrowsing];
    }
    [minPriceParentalLearnDirection appendAttributedString:copperMantissa];
    
    label.attributedText = minPriceParentalLearnDirection;
    
    
    UITapGestureRecognizer *howWakeAnd = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(duplexOperationBoostModalAsleep:)];
    [label addGestureRecognizer:howWakeAnd];
    
    return label;
}

- (void)setNameHowKitDeny:(BOOL)nameHowKitDeny {
    _nameHowKitDeny = !nameHowKitDeny;
    [self strokingGolfDependentIntegrateGoldenBuddyLabel:self];
}

- (void)duplexOperationBoostModalAsleep:(UITapGestureRecognizer *)howWakeAnd {
    ExpireSegueLabel *label = (ExpireSegueLabel *)howWakeAnd.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 kilobitsSix = [howWakeAnd locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint immutableSkinLocalCanOut = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint rowWireRowsHailConsoleCount = CGPointMake(
        kilobitsSix.x - immutableSkinLocalCanOut.x,
        kilobitsSix.y - immutableSkinLocalCanOut.y
    );
    
    
    __block BOOL postcardBlend = 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 sumHisWill;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&sumHisWill];
            
            
            CGRect usageRect = [layoutManager boundingRectForGlyphRange:sumHisWill
                                                      inTextContainer:textContainer];
            
            
            CGRect moderateSumRect = CGRectOffset(usageRect, immutableSkinLocalCanOut.x, immutableSkinLocalCanOut.y);
            
            
            if (CGRectContainsPoint(moderateSumRect, kilobitsSix)) {
                postcardBlend = YES;
                *stop = YES;
            }
        }
    }];
    
    if (postcardBlend) {
        
        
        [self strokingGolfDependentIntegrateGoldenBuddyLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:rowWireRowsHailConsoleCount
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *pintText = label.attributedText.string;
    NSRange peerIllStarKey = [pintText rangeOfString:WinNeedHang.mapSonInputIll.reuseTranspose];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, peerIllStarKey)) {
        
        
        if (self.checkingLegalPrefixSpeechPeakReplies) {
            self.checkingLegalPrefixSpeechPeakReplies();
        }
    }
}


- (void)strokingGolfDependentIntegrateGoldenBuddyLabel:(ExpireSegueLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL arrayPolar = 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 wasSelect = !_nameHowKitDeny;
        
        
        NSTextAttachment *coalesceLeast = [[NSTextAttachment alloc] init];
        
        
        UIColor *badHasColor = wasSelect ? [WinNeedHang suspendedColor]: UIColor.lightGrayColor;
        UIImage *allTrialImage = [UIImage rearrangeKeepCutterAbsentBalancedName:wasSelect ? WinNeedHang.chargePenSin.intersectSymbolAloneButValueOverhang :WinNeedHang.chargePenSin.mailWinIterationQuickHailTwo];
        
        
        coalesceLeast.image = [[allTrialImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:badHasColor];
        coalesceLeast.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:coalesceLeast range:range];
        
        _nameHowKitDeny = wasSelect;
        arrayPolar = YES;
        *stop = YES;
    }];
    
    if (arrayPolar) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
