






#import "SlideCutOwnLabel.h"
#import "RedFlexible.h"
#import "UIImage+DryImage.h"

@implementation SlideCutOwnLabel

+ (SlideCutOwnLabel *)blobPresenterLabel {
    return [self blobPresenterLabel:YES];
}

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

    NSAttributedString *settingDisparityCursorDeltaTwenty = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage detectedSeeExpectsSamplingEndsName:RedFlexible.capContinued.fingerHasSelectedSenderStreamsLenient] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        settingDisparityCursorDeltaTwenty = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = RedFlexible.daySentFaxWill.mildUnlocked;
    NSMutableAttributedString *metricVibrancy = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange suchHomeEldest = [text rangeOfString:RedFlexible.daySentFaxWill.earRetryTabNap];
    if (suchHomeEldest.location != NSNotFound) {
        [metricVibrancy addAttribute:NSForegroundColorAttributeName value:[RedFlexible northTextColor] range:suchHomeEldest];
        [metricVibrancy addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:suchHomeEldest];
    }

    
    NSMutableAttributedString *decomposeRemoteLuminanceDayWeekday = [[NSMutableAttributedString alloc] init];
    if (settingDisparityCursorDeltaTwenty) {
        [decomposeRemoteLuminanceDayWeekday appendAttributedString:settingDisparityCursorDeltaTwenty];
    }
    [decomposeRemoteLuminanceDayWeekday appendAttributedString:metricVibrancy];
    
    label.attributedText = decomposeRemoteLuminanceDayWeekday;
    
    
    UITapGestureRecognizer *maxBikeBad = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(daysCurlFixPortalMay:)];
    [label addGestureRecognizer:maxBikeBad];
    
    return label;
}

- (void)setOneDidTurnList:(BOOL)oneDidTurnList {
    _oneDidTurnList = !oneDidTurnList;
    [self ticketsPieceBlinkEditWetEraLabel:self];
}

- (void)daysCurlFixPortalMay:(UITapGestureRecognizer *)maxBikeBad {
    SlideCutOwnLabel *label = (SlideCutOwnLabel *)maxBikeBad.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 hashLatency = [maxBikeBad locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint intentCarbonFreestyleOceanLazy = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint freezingRangeDocumentAngleWrapCar = CGPointMake(
        hashLatency.x - intentCarbonFreestyleOceanLazy.x,
        hashLatency.y - intentCarbonFreestyleOceanLazy.y
    );
    
    
    __block BOOL desiredGather = 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 smileBlock;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&smileBlock];
            
            
            CGRect arrayRect = [layoutManager boundingRectForGlyphRange:smileBlock
                                                      inTextContainer:textContainer];
            
            
            CGRect messageHeadRect = CGRectOffset(arrayRect, intentCarbonFreestyleOceanLazy.x, intentCarbonFreestyleOceanLazy.y);
            
            
            if (CGRectContainsPoint(messageHeadRect, hashLatency)) {
                desiredGather = YES;
                *stop = YES;
            }
        }
    }];
    
    if (desiredGather) {
        
        
        [self ticketsPieceBlinkEditWetEraLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:freezingRangeDocumentAngleWrapCar
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *lockText = label.attributedText.string;
    NSRange suchHomeEldest = [lockText rangeOfString:RedFlexible.daySentFaxWill.earRetryTabNap];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, suchHomeEldest)) {
        
        
        if (self.levelLexiconInvalidArrangedFixtureSecurity) {
            self.levelLexiconInvalidArrangedFixtureSecurity();
        }
    }
}


- (void)ticketsPieceBlinkEditWetEraLabel:(SlideCutOwnLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL jobJobBlob = 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 earNiacin = !_oneDidTurnList;
        
        
        NSTextAttachment *autoFootAvail = [[NSTextAttachment alloc] init];
        
        
        UIColor *penTopColor = earNiacin ? [RedFlexible northTextColor]: UIColor.lightGrayColor;
        UIImage *plainTagImage = [UIImage detectedSeeExpectsSamplingEndsName:earNiacin ? RedFlexible.capContinued.typeMilesAppendedHeadPenBracket :RedFlexible.capContinued.fingerHasSelectedSenderStreamsLenient];
        
        
        autoFootAvail.image = [[plainTagImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:penTopColor];
        autoFootAvail.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:autoFootAvail range:range];
        
        _oneDidTurnList = earNiacin;
        jobJobBlob = YES;
        *stop = YES;
    }];
    
    if (jobJobBlob) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
