






#import "StepCommandLabel.h"
#import "RowAirFloor.h"
#import "UIImage+NowImage.h"

@implementation StepCommandLabel

+ (StepCommandLabel *)slowBadPinOffLabel {
    return [self slowBadPinOffLabel:YES];
}

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

    NSAttributedString *frameAboutSheBloodShrink = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage likeYouAlphaPushFriendName:RowAirFloor.loveHitOrder.invitedGraphicsUnfocusedYearSindhiEncrypted] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        frameAboutSheBloodShrink = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = RowAirFloor.iconYellowCube.agePulseTurn;
    NSMutableAttributedString *bodyWarnItsTen = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange yetBoldRestEye = [text rangeOfString:RowAirFloor.iconYellowCube.nauticalSeason];
    if (yetBoldRestEye.location != NSNotFound) {
        [bodyWarnItsTen addAttribute:NSForegroundColorAttributeName value:[RowAirFloor genderTooColor] range:yetBoldRestEye];
        [bodyWarnItsTen addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:yetBoldRestEye];
    }

    
    NSMutableAttributedString *cupSoftThreadKazakhPeriod = [[NSMutableAttributedString alloc] init];
    if (frameAboutSheBloodShrink) {
        [cupSoftThreadKazakhPeriod appendAttributedString:frameAboutSheBloodShrink];
    }
    [cupSoftThreadKazakhPeriod appendAttributedString:bodyWarnItsTen];
    
    label.attributedText = cupSoftThreadKazakhPeriod;
    
    
    UITapGestureRecognizer *freeVendor = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(fetchCircularUniqueRoundTraveled:)];
    [label addGestureRecognizer:freeVendor];
    
    return label;
}

- (void)setBasicUnwinding:(BOOL)basicUnwinding {
    _basicUnwinding = !basicUnwinding;
    [self idleCubicDrawingSwapMultipleLinerLabel:self];
}

- (void)fetchCircularUniqueRoundTraveled:(UITapGestureRecognizer *)freeVendor {
    StepCommandLabel *label = (StepCommandLabel *)freeVendor.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 menCounting = [freeVendor locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint redefinedHandlerLossReceivedSupply = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint resolvedSexSubfamilyPreferTamilRecovered = CGPointMake(
        menCounting.x - redefinedHandlerLossReceivedSupply.x,
        menCounting.y - redefinedHandlerLossReceivedSupply.y
    );
    
    
    __block BOOL malayForPrior = 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 tagalogOwn;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&tagalogOwn];
            
            
            CGRect makerRect = [layoutManager boundingRectForGlyphRange:tagalogOwn
                                                      inTextContainer:textContainer];
            
            
            CGRect pinkBundlesRect = CGRectOffset(makerRect, redefinedHandlerLossReceivedSupply.x, redefinedHandlerLossReceivedSupply.y);
            
            
            if (CGRectContainsPoint(pinkBundlesRect, menCounting)) {
                malayForPrior = YES;
                *stop = YES;
            }
        }
    }];
    
    if (malayForPrior) {
        
        
        [self idleCubicDrawingSwapMultipleLinerLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:resolvedSexSubfamilyPreferTamilRecovered
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *prepText = label.attributedText.string;
    NSRange yetBoldRestEye = [prepText rangeOfString:RowAirFloor.iconYellowCube.nauticalSeason];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, yetBoldRestEye)) {
        
        
        if (self.pairIntentsManHitArchiveNot) {
            self.pairIntentsManHitArchiveNot();
        }
    }
}


- (void)idleCubicDrawingSwapMultipleLinerLabel:(StepCommandLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL torchBrown = 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 loadFloat = !_basicUnwinding;
        
        
        NSTextAttachment *youBarTopTint = [[NSTextAttachment alloc] init];
        
        
        UIColor *wasWetColor = loadFloat ? [RowAirFloor genderTooColor]: UIColor.lightGrayColor;
        UIImage *highMindImage = [UIImage likeYouAlphaPushFriendName:loadFloat ? RowAirFloor.loveHitOrder.reuseNeedRoomGuestAudiogramWon :RowAirFloor.loveHitOrder.invitedGraphicsUnfocusedYearSindhiEncrypted];
        
        
        youBarTopTint.image = [[highMindImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:wasWetColor];
        youBarTopTint.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:youBarTopTint range:range];
        
        _basicUnwinding = loadFloat;
        torchBrown = YES;
        *stop = YES;
    }];
    
    if (torchBrown) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
