






#import "IllHisPhoneLabel.h"
#import "TopMergeNap.h"
#import "UIImage+ItsImage.h"

@implementation IllHisPhoneLabel

+ (IllHisPhoneLabel *)canSixBandMinLabel {
    return [self canSixBandMinLabel:YES];
}

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

    NSAttributedString *guestPickDifferentRespondsAscended = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage stakeMaskDownForceCallName:TopMergeNap.yetChromaUse.respectsSatisfiedHourGenderDrivenDense] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        guestPickDifferentRespondsAscended = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = TopMergeNap.turnFoggyPivot.marqueeDraft;
    NSMutableAttributedString *eraWaxFeedRoot = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange beaconRotating = [text rangeOfString:TopMergeNap.turnFoggyPivot.unsignedSample];
    if (beaconRotating.location != NSNotFound) {
        [eraWaxFeedRoot addAttribute:NSForegroundColorAttributeName value:[TopMergeNap variationColor] range:beaconRotating];
        [eraWaxFeedRoot addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:beaconRotating];
    }

    
    NSMutableAttributedString *redHellmanPrintableHeadRanked = [[NSMutableAttributedString alloc] init];
    if (guestPickDifferentRespondsAscended) {
        [redHellmanPrintableHeadRanked appendAttributedString:guestPickDifferentRespondsAscended];
    }
    [redHellmanPrintableHeadRanked appendAttributedString:eraWaxFeedRoot];
    
    label.attributedText = redHellmanPrintableHeadRanked;
    
    
    UITapGestureRecognizer *higherIdle = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(minMainElderJoiningUpload:)];
    [label addGestureRecognizer:higherIdle];
    
    return label;
}

- (void)setSideMidBackAnd:(BOOL)sideMidBackAnd {
    _sideMidBackAnd = !sideMidBackAnd;
    [self encipherDarwinSumEditorStoneFadeLabel:self];
}

- (void)minMainElderJoiningUpload:(UITapGestureRecognizer *)higherIdle {
    IllHisPhoneLabel *label = (IllHisPhoneLabel *)higherIdle.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 bestNineSub = [higherIdle locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint contactUplinkRespondIllegalFilename = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint learnedPrepReversesButterflyDepartureMultiple = CGPointMake(
        bestNineSub.x - contactUplinkRespondIllegalFilename.x,
        bestNineSub.y - contactUplinkRespondIllegalFilename.y
    );
    
    
    __block BOOL shortRawEight = 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 pascalSize;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&pascalSize];
            
            
            CGRect fetchRect = [layoutManager boundingRectForGlyphRange:pascalSize
                                                      inTextContainer:textContainer];
            
            
            CGRect faxYouAboveRect = CGRectOffset(fetchRect, contactUplinkRespondIllegalFilename.x, contactUplinkRespondIllegalFilename.y);
            
            
            if (CGRectContainsPoint(faxYouAboveRect, bestNineSub)) {
                shortRawEight = YES;
                *stop = YES;
            }
        }
    }];
    
    if (shortRawEight) {
        
        
        [self encipherDarwinSumEditorStoneFadeLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:learnedPrepReversesButterflyDepartureMultiple
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *halfText = label.attributedText.string;
    NSRange beaconRotating = [halfText rangeOfString:TopMergeNap.turnFoggyPivot.unsignedSample];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, beaconRotating)) {
        
        
        if (self.zeroBusTruncatedGracefulDependingCompact) {
            self.zeroBusTruncatedGracefulDependingCompact();
        }
    }
}


- (void)encipherDarwinSumEditorStoneFadeLabel:(IllHisPhoneLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL autoModern = 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 globalEnd = !_sideMidBackAnd;
        
        
        NSTextAttachment *oddSplitLimit = [[NSTextAttachment alloc] init];
        
        
        UIColor *hueKinColor = globalEnd ? [TopMergeNap variationColor]: UIColor.lightGrayColor;
        UIImage *mindBandImage = [UIImage stakeMaskDownForceCallName:globalEnd ? TopMergeNap.yetChromaUse.eggSeparatedCoercionDeviationCarrierMean :TopMergeNap.yetChromaUse.respectsSatisfiedHourGenderDrivenDense];
        
        
        oddSplitLimit.image = [[mindBandImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:hueKinColor];
        oddSplitLimit.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:oddSplitLimit range:range];
        
        _sideMidBackAnd = globalEnd;
        autoModern = YES;
        *stop = YES;
    }];
    
    if (autoModern) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
