






#import "MayBrownAskLabel.h"
#import "WetDoneFill.h"
#import "UIImage+TryImage.h"

@implementation MayBrownAskLabel

+ (MayBrownAskLabel *)napTimeRedBitLabel {
    return [self napTimeRedBitLabel:YES];
}

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

    NSAttributedString *gurationVeryBarMembersExporter = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage regionsScriptClearEarEllipseName:WetDoneFill.artSensitive.dryAttachedGrayEveryMongolianEmpty] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        gurationVeryBarMembersExporter = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = WetDoneFill.wideHostLooper.caseSessions;
    NSMutableAttributedString *youRingBendTwo = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange unifyEnumerate = [text rangeOfString:WetDoneFill.wideHostLooper.eachBothEffect];
    if (unifyEnumerate.location != NSNotFound) {
        [youRingBendTwo addAttribute:NSForegroundColorAttributeName value:[WetDoneFill scrollHasColor] range:unifyEnumerate];
        [youRingBendTwo addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:unifyEnumerate];
    }

    
    NSMutableAttributedString *captionPoliciesClaimEasyNautical = [[NSMutableAttributedString alloc] init];
    if (gurationVeryBarMembersExporter) {
        [captionPoliciesClaimEasyNautical appendAttributedString:gurationVeryBarMembersExporter];
    }
    [captionPoliciesClaimEasyNautical appendAttributedString:youRingBendTwo];
    
    label.attributedText = captionPoliciesClaimEasyNautical;
    
    
    UITapGestureRecognizer *indexedDog = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(workNordicNominalCondensedElement:)];
    [label addGestureRecognizer:indexedDog];
    
    return label;
}

- (void)setLogDigitAddYou:(BOOL)logDigitAddYou {
    _logDigitAddYou = !logDigitAddYou;
    [self preciseReloadPlayingFeatMutationsAmbiguousLabel:self];
}

- (void)workNordicNominalCondensedElement:(UITapGestureRecognizer *)indexedDog {
    MayBrownAskLabel *label = (MayBrownAskLabel *)indexedDog.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 decisionLog = [indexedDog locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint orderRenewReadyDialogNumber = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint mapWristDrainLoveReturningCommand = CGPointMake(
        decisionLog.x - orderRenewReadyDialogNumber.x,
        decisionLog.y - orderRenewReadyDialogNumber.y
    );
    
    
    __block BOOL portEarSobOpt = 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 centersOne;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&centersOne];
            
            
            CGRect themeRect = [layoutManager boundingRectForGlyphRange:centersOne
                                                      inTextContainer:textContainer];
            
            
            CGRect sinSignZeroRect = CGRectOffset(themeRect, orderRenewReadyDialogNumber.x, orderRenewReadyDialogNumber.y);
            
            
            if (CGRectContainsPoint(sinSignZeroRect, decisionLog)) {
                portEarSobOpt = YES;
                *stop = YES;
            }
        }
    }];
    
    if (portEarSobOpt) {
        
        
        [self preciseReloadPlayingFeatMutationsAmbiguousLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:mapWristDrainLoveReturningCommand
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *stepText = label.attributedText.string;
    NSRange unifyEnumerate = [stepText rangeOfString:WetDoneFill.wideHostLooper.eachBothEffect];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, unifyEnumerate)) {
        
        
        if (self.readerIssueGaelicCountCascadeBezel) {
            self.readerIssueGaelicCountCascadeBezel();
        }
    }
}


- (void)preciseReloadPlayingFeatMutationsAmbiguousLabel:(MayBrownAskLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL useUseSide = 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 offAppear = !_logDigitAddYou;
        
        
        NSTextAttachment *getFunDerived = [[NSTextAttachment alloc] init];
        
        
        UIColor *memberColor = offAppear ? [WetDoneFill scrollHasColor]: UIColor.lightGrayColor;
        UIImage *sockRateImage = [UIImage regionsScriptClearEarEllipseName:offAppear ? WetDoneFill.artSensitive.hailSwappedFatalCascadePasswordsSafari :WetDoneFill.artSensitive.dryAttachedGrayEveryMongolianEmpty];
        
        
        getFunDerived.image = [[sockRateImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:memberColor];
        getFunDerived.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:getFunDerived range:range];
        
        _logDigitAddYou = offAppear;
        useUseSide = YES;
        *stop = YES;
    }];
    
    if (useUseSide) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
