






#import "HaveSaveWinLabel.h"
#import "AdverbTamil.h"
#import "UIImage+BusImage.h"

@implementation HaveSaveWinLabel

+ (HaveSaveWinLabel *)compileFollowLabel {
    return [self compileFollowLabel:YES];
}

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

    NSAttributedString *canonVariableCallbackStillReset = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage smoothBinBadConnectClickedName:AdverbTamil.bedUndoReuse.workspaceActionBelowHexPlainOunces] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        canonVariableCallbackStillReset = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = AdverbTamil.takeCellTagBus.sequencerNot;
    NSMutableAttributedString *hertzPremature = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange binCupOutAudit = [text rangeOfString:AdverbTamil.takeCellTagBus.presentedLower];
    if (binCupOutAudit.location != NSNotFound) {
        [hertzPremature addAttribute:NSForegroundColorAttributeName value:[AdverbTamil sexCopperColor] range:binCupOutAudit];
        [hertzPremature addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:binCupOutAudit];
    }

    
    NSMutableAttributedString *externalBecomeBendChangedChamber = [[NSMutableAttributedString alloc] init];
    if (canonVariableCallbackStillReset) {
        [externalBecomeBendChangedChamber appendAttributedString:canonVariableCallbackStillReset];
    }
    [externalBecomeBendChangedChamber appendAttributedString:hertzPremature];
    
    label.attributedText = externalBecomeBendChangedChamber;
    
    
    UITapGestureRecognizer *audibleCup = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(slopePrinterMantissaEarClick:)];
    [label addGestureRecognizer:audibleCup];
    
    return label;
}

- (void)setPauseTowerHash:(BOOL)pauseTowerHash {
    _pauseTowerHash = !pauseTowerHash;
    [self intrinsicCanVolatileTorchHandshakeHiddenLabel:self];
}

- (void)slopePrinterMantissaEarClick:(UITapGestureRecognizer *)audibleCup {
    HaveSaveWinLabel *label = (HaveSaveWinLabel *)audibleCup.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 ourStoreOne = [audibleCup locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint radiansAttitudeFilmHueResult = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint funEightForGatewaysSafetyFax = CGPointMake(
        ourStoreOne.x - radiansAttitudeFilmHueResult.x,
        ourStoreOne.y - radiansAttitudeFilmHueResult.y
    );
    
    
    __block BOOL brandEvaluate = 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 folderFeet;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&folderFeet];
            
            
            CGRect styleRect = [layoutManager boundingRectForGlyphRange:folderFeet
                                                      inTextContainer:textContainer];
            
            
            CGRect meanNetJustRect = CGRectOffset(styleRect, radiansAttitudeFilmHueResult.x, radiansAttitudeFilmHueResult.y);
            
            
            if (CGRectContainsPoint(meanNetJustRect, ourStoreOne)) {
                brandEvaluate = YES;
                *stop = YES;
            }
        }
    }];
    
    if (brandEvaluate) {
        
        
        [self intrinsicCanVolatileTorchHandshakeHiddenLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:funEightForGatewaysSafetyFax
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *dashText = label.attributedText.string;
    NSRange binCupOutAudit = [dashText rangeOfString:AdverbTamil.takeCellTagBus.presentedLower];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, binCupOutAudit)) {
        
        
        if (self.logoOppositeExecFreezingSignatureDrain) {
            self.logoOppositeExecFreezingSignatureDrain();
        }
    }
}


- (void)intrinsicCanVolatileTorchHandshakeHiddenLabel:(HaveSaveWinLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL notAutoHis = 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 enclosing = !_pauseTowerHash;
        
        
        NSTextAttachment *redElderBadge = [[NSTextAttachment alloc] init];
        
        
        UIColor *optionColor = enclosing ? [AdverbTamil sexCopperColor]: UIColor.lightGrayColor;
        UIImage *obscuredImage = [UIImage smoothBinBadConnectClickedName:enclosing ? AdverbTamil.bedUndoReuse.japaneseRawRawTextualDrawRecipient :AdverbTamil.bedUndoReuse.workspaceActionBelowHexPlainOunces];
        
        
        redElderBadge.image = [[obscuredImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:optionColor];
        redElderBadge.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:redElderBadge range:range];
        
        _pauseTowerHash = enclosing;
        notAutoHis = YES;
        *stop = YES;
    }];
    
    if (notAutoHis) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
