






#import "DroppedMindLabel.h"
#import "BadMeanSame.h"
#import "UIImage+EraImage.h"

@implementation DroppedMindLabel

+ (DroppedMindLabel *)predictedFactLabel {
    return [self predictedFactLabel:YES];
}

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

    NSAttributedString *earRecorderSiteEndSpell = nil;
    if (isCheckBox) {
        
        NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
        UIImage *templateImage = [[UIImage mediumBackwardsReceiveDeliveryVersionsName:BadMeanSame.clockwiseSun.nearPagerLatvianRoomAppendedStart] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
        attachment.image = templateImage; 
        
        attachment.bounds = CGRectMake(0, -5, 20, 20);
        earRecorderSiteEndSpell = [NSAttributedString attributedStringWithAttachment:attachment];
    }

    
    NSString *text = BadMeanSame.bikeVeryIcyOne.revisionsTip;
    NSMutableAttributedString *bagTwoForkEcho = [[NSMutableAttributedString alloc] initWithString:text];
    
    
    NSRange edgaArtAtomWay = [text rangeOfString:BadMeanSame.bikeVeryIcyOne.saySplatTipWax];
    if (edgaArtAtomWay.location != NSNotFound) {
        [bagTwoForkEcho addAttribute:NSForegroundColorAttributeName value:[BadMeanSame currentlyColor] range:edgaArtAtomWay];
        [bagTwoForkEcho addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:edgaArtAtomWay];
    }

    
    NSMutableAttributedString *endLuminanceDrivenGroupingStream = [[NSMutableAttributedString alloc] init];
    if (earRecorderSiteEndSpell) {
        [endLuminanceDrivenGroupingStream appendAttributedString:earRecorderSiteEndSpell];
    }
    [endLuminanceDrivenGroupingStream appendAttributedString:bagTwoForkEcho];
    
    label.attributedText = endLuminanceDrivenGroupingStream;
    
    
    UITapGestureRecognizer *mixEntropy = [[UITapGestureRecognizer alloc] initWithTarget:label action:@selector(clangSegueOceanManganeseChat:)];
    [label addGestureRecognizer:mixEntropy];
    
    return label;
}

- (void)setStreetEllipsis:(BOOL)streetEllipsis {
    _streetEllipsis = !streetEllipsis;
    [self maleCallRenewalRedNowSquashLabel:self];
}

- (void)clangSegueOceanManganeseChat:(UITapGestureRecognizer *)mixEntropy {
    DroppedMindLabel *label = (DroppedMindLabel *)mixEntropy.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 dropPopSame = [mixEntropy locationInView:label];
    CGRect usedRect = [layoutManager usedRectForTextContainer:textContainer];
    CGPoint leaseCountLexicalEditMultiple = CGPointMake(
        (label.bounds.size.width - usedRect.size.width) / 2,   
        (label.bounds.size.height - usedRect.size.height) / 2  
    );
    
    
    CGPoint bundleRopeChamberHerShoulderMoment = CGPointMake(
        dropPopSame.x - leaseCountLexicalEditMultiple.x,
        dropPopSame.y - leaseCountLexicalEditMultiple.y
    );
    
    
    __block BOOL pressFairThat = 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 coastShake;
            [layoutManager glyphRangeForCharacterRange:range actualCharacterRange:&coastShake];
            
            
            CGRect gradeRect = [layoutManager boundingRectForGlyphRange:coastShake
                                                      inTextContainer:textContainer];
            
            
            CGRect outKinIdiomRect = CGRectOffset(gradeRect, leaseCountLexicalEditMultiple.x, leaseCountLexicalEditMultiple.y);
            
            
            if (CGRectContainsPoint(outKinIdiomRect, dropPopSame)) {
                pressFairThat = YES;
                *stop = YES;
            }
        }
    }];
    
    if (pressFairThat) {
        
        
        [self maleCallRenewalRedNowSquashLabel:label];
        return;
    }
    
    
    NSUInteger characterIndex = [layoutManager characterIndexForPoint:bundleRopeChamberHerShoulderMoment
                                                    inTextContainer:textContainer
                           fractionOfDistanceBetweenInsertionPoints:NULL];
    
    NSString *holdText = label.attributedText.string;
    NSRange edgaArtAtomWay = [holdText rangeOfString:BadMeanSame.bikeVeryIcyOne.saySplatTipWax];
    
    if (characterIndex != NSNotFound && NSLocationInRange(characterIndex, edgaArtAtomWay)) {
        
        
        if (self.obscuredImmutableSobFormatStopElevation) {
            self.obscuredImmutableSobFormatStopElevation();
        }
    }
}


- (void)maleCallRenewalRedNowSquashLabel:(DroppedMindLabel *)label {
    NSMutableAttributedString *attributedText = [label.attributedText mutableCopy];
    __block BOOL leapCeltic = 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 legalRare = !_streetEllipsis;
        
        
        NSTextAttachment *napOptBagEasy = [[NSTextAttachment alloc] init];
        
        
        UIColor *threadColor = legalRare ? [BadMeanSame currentlyColor]: UIColor.lightGrayColor;
        UIImage *selectorImage = [UIImage mediumBackwardsReceiveDeliveryVersionsName:legalRare ? BadMeanSame.clockwiseSun.modifiedIntegralRadialMotionWonReleased :BadMeanSame.clockwiseSun.nearPagerLatvianRoomAppendedStart];
        
        
        napOptBagEasy.image = [[selectorImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]
                                imageWithTintColor:threadColor];
        napOptBagEasy.bounds = oldAttachment.bounds;
        
        
        [attributedText removeAttribute:NSAttachmentAttributeName range:range];
        [attributedText addAttribute:NSAttachmentAttributeName value:napOptBagEasy range:range];
        
        _streetEllipsis = legalRare;
        leapCeltic = YES;
        *stop = YES;
    }];
    
    if (leapCeltic) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIView transitionWithView:label
                              duration:0.3
                               options:UIViewAnimationOptionTransitionCrossDissolve
                            animations:^{
                                label.attributedText = attributedText;
                            } completion:nil];
            [label setNeedsDisplay];
        });
    }
}

@end
