






#import "LargeStrideLabel.h"
#import "MainMinimal.h"
#import "UIImage+OptImage.h"

@implementation LargeStrideLabel

+ (LargeStrideLabel *)tintHangBeginLabel {
    return [self tintHangBeginLabel:YES];
}

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

    NSAttributedString *roleStrokeVersionsKitAnimate = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage volumesSerialNearestContextCreatedName:MainMinimal.nordicPubTen.sunPencilSunBirthDuplicateRed] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        roleStrokeVersionsKitAnimate = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = MainMinimal.tiedTagCertTen.localityChat;
    NSMutableAttributedString *transposeInset = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange sentAbortAudio = [text rangeOfString:MainMinimal.tiedTagCertTen.errorSolidPeak];
    if (sentAbortAudio.location != NSNotFound) {
        [transposeInset addAttribute:NSForegroundColorAttributeName value:[MainMinimal anyUpsideColor] range:sentAbortAudio];
        [transposeInset addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:sentAbortAudio];
    }

    
    NSMutableAttributedString *minuteSkippedPutWeightedNone = [[NSMutableAttributedString alloc] init];
    if (roleStrokeVersionsKitAnimate) {
        [minuteSkippedPutWeightedNone appendAttributedString:roleStrokeVersionsKitAnimate];
    }
    [minuteSkippedPutWeightedNone appendAttributedString:transposeInset];
    
    label.attributedText = minuteSkippedPutWeightedNone;
    
    
    UITapGestureRecognizer *toolSubmit = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(seasonGroupedCenterSentencesSpanish:)];
    [label addGestureRecognizer:toolSubmit];
    
    return label;
}

- (void)setGivenFireSlope:(BOOL)givenFireSlope {
    _givenFireSlope = !givenFireSlope;
    [self sharingRetSetupGrammarFullyGigabitsLabel:self];
}

- (void)seasonGroupedCenterSentencesSpanish:(UITapGestureRecognizer *)toolSubmit {
    LargeStrideLabel *label = (LargeStrideLabel *)toolSubmit.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 autoPopover = [toolSubmit locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint stickyProximityProposalMetabolicMovement = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint quarterMathHueLearnCalendarSnap = CGPointMake(
        autoPopover.x - stickyProximityProposalMetabolicMovement.x,
        autoPopover.y - stickyProximityProposalMetabolicMovement.y
    );
    
    
    __block BOOL wrapDueSunBag = 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 limitFound;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&limitFound];
            
            
            CGRect danceRect = [layoutManager boundingRectForGlyphRange:limitFound
                                                      inTextContainer:textContainer];
            
            
            CGRect discardBandRect = CGRectOffset(danceRect, stickyProximityProposalMetabolicMovement.x, stickyProximityProposalMetabolicMovement.y);
            
            
            if (CGRectContainsPoint(discardBandRect, autoPopover)) {
                wrapDueSunBag = YES;
                *stop = YES;
            }
        }
    }];
    
    if (wrapDueSunBag) {
        
        
        [self sharingRetSetupGrammarFullyGigabitsLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:quarterMathHueLearnCalendarSnap
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *passText = label.attributedText.string;
    NSRange sentAbortAudio = [passText rangeOfString:MainMinimal.tiedTagCertTen.errorSolidPeak];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, sentAbortAudio)) {
        
        
        if (self.periodicSpineProteinSeleniumDivideNote) {
            self.periodicSpineProteinSeleniumDivideNote();
        }
    }
}


- (void)sharingRetSetupGrammarFullyGigabitsLabel:(LargeStrideLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL netWetTeam = 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 musicLast = !_givenFireSlope;
        
        
        NSTextAttachment *binaryFisheye = [[NSTextAttachment alloc] init];
        
        
        UIColor *cupZipColor = musicLast ? [MainMinimal anyUpsideColor]: UIColor.lightGrayColor;
        UIImage *netLargeImage = [UIImage volumesSerialNearestContextCreatedName:musicLast ? MainMinimal.nordicPubTen.quotesCompositeInnerRoundRetryCancelled :MainMinimal.nordicPubTen.sunPencilSunBirthDuplicateRed];
        
        
        binaryFisheye.image = [[netLargeImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:cupZipColor];
        binaryFisheye.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:binaryFisheye range:range];
        
        _givenFireSlope = musicLast;
        netWetTeam = YES;
        *stop = YES;
    }];
    
    if (netWetTeam) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
