






#import "RevertSheetLabel.h"
#import "TextualTemp.h"
#import "UIImage+GetImage.h"

@implementation RevertSheetLabel

+ (RevertSheetLabel *)hitWetDateItsLabel {
    return [self hitWetDateItsLabel:YES];
}

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

    NSAttributedString *linkNiacinRetainRestYoungest = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage workGrowBeginAnimatorExcludedName:TextualTemp.cancelsParse.chinaMutableSpringTapsLoadingSignal] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        linkNiacinRetainRestYoungest = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = TextualTemp.mindSnowHeader.estonianAuto;
    NSMutableAttributedString *oddGreekPanRaw = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange acuteEstimated = [text rangeOfString:TextualTemp.mindSnowHeader.fitMixSumLarge];
    if (acuteEstimated.location != NSNotFound) {
        [oddGreekPanRaw addAttribute:NSForegroundColorAttributeName value:[TextualTemp longBoostColor] range:acuteEstimated];
        [oddGreekPanRaw addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:acuteEstimated];
    }

    
    NSMutableAttributedString *friendRemainderAmbientClearedAltitude = [[NSMutableAttributedString alloc] init];
    if (linkNiacinRetainRestYoungest) {
        [friendRemainderAmbientClearedAltitude appendAttributedString:linkNiacinRetainRestYoungest];
    }
    [friendRemainderAmbientClearedAltitude appendAttributedString:oddGreekPanRaw];
    
    label.attributedText = friendRemainderAmbientClearedAltitude;
    
    
    UITapGestureRecognizer *tipSymptom = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(gurationFloorBusyComparedAny:)];
    [label addGestureRecognizer:tipSymptom];
    
    return label;
}

- (void)setBusFastPullOld:(BOOL)busFastPullOld {
    _busFastPullOld = !busFastPullOld;
    [self speakEstonianCommitObserverLossyLastLabel:self];
}

- (void)gurationFloorBusyComparedAny:(UITapGestureRecognizer *)tipSymptom {
    RevertSheetLabel *label = (RevertSheetLabel *)tipSymptom.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 dayDidDance = [tipSymptom locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint heavyPubIntrinsicMenRedirects = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint doneLocalizedTruncatesSampleBaseballBlack = CGPointMake(
        dayDidDance.x - heavyPubIntrinsicMenRedirects.x,
        dayDidDance.y - heavyPubIntrinsicMenRedirects.y
    );
    
    
    __block BOOL wideProviding = 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 quitTooIts;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&quitTooIts];
            
            
            CGRect powerRect = [layoutManager boundingRectForGlyphRange:quitTooIts
                                                      inTextContainer:textContainer];
            
            
            CGRect moleWetVeryRect = CGRectOffset(powerRect, heavyPubIntrinsicMenRedirects.x, heavyPubIntrinsicMenRedirects.y);
            
            
            if (CGRectContainsPoint(moleWetVeryRect, dayDidDance)) {
                wideProviding = YES;
                *stop = YES;
            }
        }
    }];
    
    if (wideProviding) {
        
        
        [self speakEstonianCommitObserverLossyLastLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:doneLocalizedTruncatesSampleBaseballBlack
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *itemText = label.attributedText.string;
    NSRange acuteEstimated = [itemText rangeOfString:TextualTemp.mindSnowHeader.fitMixSumLarge];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, acuteEstimated)) {
        
        
        if (self.estonianMoleCleanupDeprecateFreeIll) {
            self.estonianMoleCleanupDeprecateFreeIll();
        }
    }
}


- (void)speakEstonianCommitObserverLossyLastLabel:(RevertSheetLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL butPutSkin = 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 exitsBurn = !_busFastPullOld;
        
        
        NSTextAttachment *restObserving = [[NSTextAttachment alloc] init];
        
        
        UIColor *eggEyeColor = exitsBurn ? [TextualTemp longBoostColor]: UIColor.lightGrayColor;
        UIImage *subgroupImage = [UIImage workGrowBeginAnimatorExcludedName:exitsBurn ? TextualTemp.cancelsParse.sevenUnwrapWayLabelScalePass :TextualTemp.cancelsParse.chinaMutableSpringTapsLoadingSignal];
        
        
        restObserving.image = [[subgroupImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:eggEyeColor];
        restObserving.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:restObserving range:range];
        
        _busFastPullOld = exitsBurn;
        butPutSkin = YES;
        *stop = YES;
    }];
    
    if (butPutSkin) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
