






#import "RadixWinMidLabel.h"
#import "ClaimMaxBig.h"
#import "UIImage+BagImage.h"

@implementation RadixWinMidLabel

+ (RadixWinMidLabel *)useExecuteMapLabel {
    return [self useExecuteMapLabel:YES];
}

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

    NSAttributedString *recordingMildCivilDisplayedAge = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage earResumeRawOwnFatName:ClaimMaxBig.applierPatch.sonResolvingPickGrayCautionUsage] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        recordingMildCivilDisplayedAge = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = ClaimMaxBig.allFeedEarGolf.ownLowerHand;
    NSMutableAttributedString *answerSortSort = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange civilMacintosh = [text rangeOfString:ClaimMaxBig.allFeedEarGolf.losePrettyThin];
    if (civilMacintosh.location != NSNotFound) {
        [answerSortSort addAttribute:NSForegroundColorAttributeName value:[ClaimMaxBig nineSlideColor] range:civilMacintosh];
        [answerSortSort addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:civilMacintosh];
    }

    
    NSMutableAttributedString *smoothedBadIncomingMinFork = [[NSMutableAttributedString alloc] init];
    if (recordingMildCivilDisplayedAge) {
        [smoothedBadIncomingMinFork appendAttributedString:recordingMildCivilDisplayedAge];
    }
    [smoothedBadIncomingMinFork appendAttributedString:answerSortSort];
    
    label.attributedText = smoothedBadIncomingMinFork;
    
    
    UITapGestureRecognizer *dayFlipped = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(growBrushAlienPushSwipe:)];
    [label addGestureRecognizer:dayFlipped];
    
    return label;
}

- (void)setCutChatRunPink:(BOOL)cutChatRunPink {
    _cutChatRunPink = !cutChatRunPink;
    [self trialEnhanceAgentFitMixBouncingLabel:self];
}

- (void)growBrushAlienPushSwipe:(UITapGestureRecognizer *)dayFlipped {
    RadixWinMidLabel *label = (RadixWinMidLabel *)dayFlipped.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 expertRebus = [dayFlipped locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint passiveChineseNorthWarningGrow = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint optTheFactoriesSquareInvertRest = CGPointMake(
        expertRebus.x - passiveChineseNorthWarningGrow.x,
        expertRebus.y - passiveChineseNorthWarningGrow.y
    );
    
    
    __block BOOL elevationJust = 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 dragOldRun;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&dragOldRun];
            
            
            CGRect focusRect = [layoutManager boundingRectForGlyphRange:dragOldRun
                                                      inTextContainer:textContainer];
            
            
            CGRect auditTooBinRect = CGRectOffset(focusRect, passiveChineseNorthWarningGrow.x, passiveChineseNorthWarningGrow.y);
            
            
            if (CGRectContainsPoint(auditTooBinRect, expertRebus)) {
                elevationJust = YES;
                *stop = YES;
            }
        }
    }];
    
    if (elevationJust) {
        
        
        [self trialEnhanceAgentFitMixBouncingLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:optTheFactoriesSquareInvertRest
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *hairText = label.attributedText.string;
    NSRange civilMacintosh = [hairText rangeOfString:ClaimMaxBig.allFeedEarGolf.losePrettyThin];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, civilMacintosh)) {
        
        
        if (self.portionShutterExtractRankQuotesOne) {
            self.portionShutterExtractRankQuotesOne();
        }
    }
}


- (void)trialEnhanceAgentFitMixBouncingLabel:(RadixWinMidLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL longestAdd = 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 numerator = !_cutChatRunPink;
        
        
        NSTextAttachment *instancesMust = [[NSTextAttachment alloc] init];
        
        
        UIColor *minNotColor = numerator ? [ClaimMaxBig nineSlideColor]: UIColor.lightGrayColor;
        UIImage *askInterImage = [UIImage earResumeRawOwnFatName:numerator ? ClaimMaxBig.applierPatch.smileAccessedKilowattsSystolicCatText :ClaimMaxBig.applierPatch.sonResolvingPickGrayCautionUsage];
        
        
        instancesMust.image = [[askInterImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:minNotColor];
        instancesMust.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:instancesMust range:range];
        
        _cutChatRunPink = numerator;
        longestAdd = YES;
        *stop = YES;
    }];
    
    if (longestAdd) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
